Discussion:
How to get Forms.Panel control to fire key events?
(too old to reply)
DaveTMG
2010-03-10 17:56:02 UTC
Permalink
I am working on an Windows Forms application using VS 2008 and C#. The
application is very trivial to this point with just three components: the
form, an outer panel and an inner panel. The form hosts the outer panel and
the outer panel hosts the inner panel.

I have set up event handlers for the inner panel to test for which events
are being seen by the panel. To my surprize the panel does not fire any of
the key events or the mouse wheel event, but the mouse click and move events
are fired just fine. I have also noted that the panels never gets focus.
Here is the code:

public PanelEventTest()
{
InitializeComponent();

pnlInner.KeyDown += new KeyEventHandler( pnlInner_KeyDown );
pnlInner.KeyUp += new KeyEventHandler( pnlInner_KeyUp );
pnlInner.PreviewKeyDown += new PreviewKeyDownEventHandler(
pnlInner_PreviewKeyDown );
pnlInner.MouseDown += new MouseEventHandler( pnlInner_MouseDown );
pnlInner.MouseUp += new MouseEventHandler( pnlInner_MouseUp );
pnlInner.MouseMove += new MouseEventHandler( pnlInner_MouseMove );
pnlInner.MouseWheel += new MouseEventHandler( pnlInner_MouseWheel );
pnlInner.MouseDoubleClick += new MouseEventHandler(
pnlInner_MouseDoubleClick );
}

I really need to see the key events in the inner panel. The intent is to
use the panel as a Direct3D drawing surface and have the user interact with
the displayed graphics by using various mouse actions in combination with
keys like Shift and Control. A left mouse click by itself might mean center
image at the current mouse location and a left mouse click with the Shift key
held down might mean center and zoom in the image.

How can I get the panel to fire the above key related events?

Thanks,
Dave
DaveTMG
2010-03-12 21:52:01 UTC
Permalink
Is there not a Microsoft or MVP person monitoring this discussion group?

I have a paid subscription and was expecting some help within 48 hours. Is
there a more appropriate group for my post?

Thanks,
Dave
Post by DaveTMG
I am working on an Windows Forms application using VS 2008 and C#. The
application is very trivial to this point with just three components: the
form, an outer panel and an inner panel. The form hosts the outer panel and
the outer panel hosts the inner panel.
I have set up event handlers for the inner panel to test for which events
are being seen by the panel. To my surprize the panel does not fire any of
the key events or the mouse wheel event, but the mouse click and move events
are fired just fine. I have also noted that the panels never gets focus.
public PanelEventTest()
{
InitializeComponent();
pnlInner.KeyDown += new KeyEventHandler( pnlInner_KeyDown );
pnlInner.KeyUp += new KeyEventHandler( pnlInner_KeyUp );
pnlInner.PreviewKeyDown += new PreviewKeyDownEventHandler(
pnlInner_PreviewKeyDown );
pnlInner.MouseDown += new MouseEventHandler( pnlInner_MouseDown );
pnlInner.MouseUp += new MouseEventHandler( pnlInner_MouseUp );
pnlInner.MouseMove += new MouseEventHandler( pnlInner_MouseMove );
pnlInner.MouseWheel += new MouseEventHandler( pnlInner_MouseWheel );
pnlInner.MouseDoubleClick += new MouseEventHandler(
pnlInner_MouseDoubleClick );
}
I really need to see the key events in the inner panel. The intent is to
use the panel as a Direct3D drawing surface and have the user interact with
the displayed graphics by using various mouse actions in combination with
keys like Shift and Control. A left mouse click by itself might mean center
image at the current mouse location and a left mouse click with the Shift key
held down might mean center and zoom in the image.
How can I get the panel to fire the above key related events?
Thanks,
Dave
brian
2010-04-07 13:27:02 UTC
Permalink
I'm no MVP.. but.. I am working with VS 2008 and Panels in my WinForms
application.

One thing I do know (which you've likely already discovered elsewhere by
now) is that you need to set a Panel's "TabStop" property to *true* before
it is allowed to receive focus.

Also, in my experimentation, if the Panel does not contain any focusable
controls (like a Button, DataGridView or a TextBox, etc) then it's STILL not
likely that the Panel can recieve focus. I have a custom design where my
panel is initially very small, with a top-docked Label inside of it.. and
when the user clicks on the Label, the panel expands and I turn on the
visibility of other controls (a windowshade effect).

Everything works fine for me, except I can't get this thing to work if I
want the user to manipulate multiple windowshade panels via their keyboard.
Part of my problem, is that the Label is not a focusable control (and the
other controls that are focusable have their visibility set to false). I
could swap out my clickable Label with a Button control, but I do not like
their appearance when focused.. so.. I'm still experimenting.

Anyway.. I hope some of what I've shared above helps out your situration.
Post by DaveTMG
Is there not a Microsoft or MVP person monitoring this discussion group?
I have a paid subscription and was expecting some help within 48 hours. Is
there a more appropriate group for my post?
Thanks,
Dave
Post by DaveTMG
I am working on an Windows Forms application using VS 2008 and C#. The
application is very trivial to this point with just three components: the
form, an outer panel and an inner panel. The form hosts the outer panel and
the outer panel hosts the inner panel.
I have set up event handlers for the inner panel to test for which events
are being seen by the panel. To my surprize the panel does not fire any of
the key events or the mouse wheel event, but the mouse click and move events
are fired just fine. I have also noted that the panels never gets focus.
public PanelEventTest()
{
InitializeComponent();
pnlInner.KeyDown += new KeyEventHandler( pnlInner_KeyDown );
pnlInner.KeyUp += new KeyEventHandler( pnlInner_KeyUp );
pnlInner.PreviewKeyDown += new PreviewKeyDownEventHandler(
pnlInner_PreviewKeyDown );
pnlInner.MouseDown += new MouseEventHandler( pnlInner_MouseDown );
pnlInner.MouseUp += new MouseEventHandler( pnlInner_MouseUp );
pnlInner.MouseMove += new MouseEventHandler( pnlInner_MouseMove );
pnlInner.MouseWheel += new MouseEventHandler( pnlInner_MouseWheel );
pnlInner.MouseDoubleClick += new MouseEventHandler(
pnlInner_MouseDoubleClick );
}
I really need to see the key events in the inner panel. The intent is to
use the panel as a Direct3D drawing surface and have the user interact with
the displayed graphics by using various mouse actions in combination with
keys like Shift and Control. A left mouse click by itself might mean center
image at the current mouse location and a left mouse click with the Shift key
held down might mean center and zoom in the image.
How can I get the panel to fire the above key related events?
Thanks,
Dave
brian
2010-04-07 13:29:01 UTC
Permalink
One other thing that comes to mind, is that you need to set the "KeyPreview"
property of the overall Form to *true*
Post by DaveTMG
Is there not a Microsoft or MVP person monitoring this discussion group?
I have a paid subscription and was expecting some help within 48 hours. Is
there a more appropriate group for my post?
Thanks,
Dave
Post by DaveTMG
I am working on an Windows Forms application using VS 2008 and C#. The
application is very trivial to this point with just three components: the
form, an outer panel and an inner panel. The form hosts the outer panel and
the outer panel hosts the inner panel.
I have set up event handlers for the inner panel to test for which events
are being seen by the panel. To my surprize the panel does not fire any of
the key events or the mouse wheel event, but the mouse click and move events
are fired just fine. I have also noted that the panels never gets focus.
public PanelEventTest()
{
InitializeComponent();
pnlInner.KeyDown += new KeyEventHandler( pnlInner_KeyDown );
pnlInner.KeyUp += new KeyEventHandler( pnlInner_KeyUp );
pnlInner.PreviewKeyDown += new PreviewKeyDownEventHandler(
pnlInner_PreviewKeyDown );
pnlInner.MouseDown += new MouseEventHandler( pnlInner_MouseDown );
pnlInner.MouseUp += new MouseEventHandler( pnlInner_MouseUp );
pnlInner.MouseMove += new MouseEventHandler( pnlInner_MouseMove );
pnlInner.MouseWheel += new MouseEventHandler( pnlInner_MouseWheel );
pnlInner.MouseDoubleClick += new MouseEventHandler(
pnlInner_MouseDoubleClick );
}
I really need to see the key events in the inner panel. The intent is to
use the panel as a Direct3D drawing surface and have the user interact with
the displayed graphics by using various mouse actions in combination with
keys like Shift and Control. A left mouse click by itself might mean center
image at the current mouse location and a left mouse click with the Shift key
held down might mean center and zoom in the image.
How can I get the panel to fire the above key related events?
Thanks,
Dave
Chris Becke
2010-04-07 14:27:35 UTC
Permalink
Post by DaveTMG
Is there not a Microsoft or MVP person monitoring this discussion group?
I have a paid subscription and was expecting some help within 48 hours. Is
there a more appropriate group for my post?
Thanks,
Dave
Post by DaveTMG
I am working on an Windows Forms application using VS 2008 and C#. The
application is very trivial to this point with just three components: the
form, an outer panel and an inner panel. The form hosts the outer panel and
the outer panel hosts the inner panel.
I have set up event handlers for the inner panel to test for which events
are being seen by the panel. To my surprize the panel does not fire any of
the key events or the mouse wheel event, but the mouse click and move events
are fired just fine. I have also noted that the panels never gets focus.
public PanelEventTest()
{
InitializeComponent();
pnlInner.KeyDown += new KeyEventHandler( pnlInner_KeyDown );
pnlInner.KeyUp += new KeyEventHandler( pnlInner_KeyUp );
pnlInner.PreviewKeyDown += new PreviewKeyDownEventHandler(
pnlInner_PreviewKeyDown );
pnlInner.MouseDown += new MouseEventHandler( pnlInner_MouseDown );
pnlInner.MouseUp += new MouseEventHandler( pnlInner_MouseUp );
pnlInner.MouseMove += new MouseEventHandler( pnlInner_MouseMove );
pnlInner.MouseWheel += new MouseEventHandler( pnlInner_MouseWheel );
pnlInner.MouseDoubleClick += new MouseEventHandler(
pnlInner_MouseDoubleClick );
}
I really need to see the key events in the inner panel. The intent is to
use the panel as a Direct3D drawing surface and have the user interact with
the displayed graphics by using various mouse actions in combination with
keys like Shift and Control. A left mouse click by itself might mean center
image at the current mouse location and a left mouse click with the Shift key
held down might mean center and zoom in the image.
How can I get the panel to fire the above key related events?
Thanks,
Dave
according to the managed newsgroups page on msdn, this is one of the
newsgroups that should be monitored with that 48 hour turn around.

Perhaps they cancelled the managed newsgroups program and forgot to tell us.

All we have to do is post with the email address associated with our
subscription right?

Continue reading on narkive:
Loading...