By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

How to prevent keydown events on toolbar

P: n/a
Dear group,

I am trying to move a panel (panel2) around which is inside another
panel (panel1). I want the user to be able to use the arrow keys on the
keyboard.

However when I press either arrow key, focus is set to my toolbar
(toolbar1) and you see focus going from pushbutton to pushbutton.

I've tried keydown events on mybase, panel1, panel2 and finally only
this is working:

Private Sub ToolBar1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ToolBar1.KeyDown

If e.KeyCode = Keys.Right Then

panel2.location = [etc]

End If

End Sub

However this is not a nice workaround. If the user presses right or
left several times in a row or holds down the key, you see the panel
moving alright but also the toolbar gets repainted over and over again
to a point it can't repaint quickly enough and disappears a moment.

So both the panel is moving and the focus is moving over the
pushbuttons on the toolbar.

Can someone tell me how to tell the toolbar _not_ to catch keydown
events and let the panel1, panel2 or mybase or even the form handle
this (where it should be in this situation).

Help is appreciated!

Kind Regards,
Martin.

Dec 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Use the following code in your form to handle the keypress event.

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Right Then
'Move the Panel
Return True
End If
Return MyBase.ProcessDialogKey(keyData)
End Function

Hope this helps.

Sugan.

ma*****@hotmail.com wrote:
Dear group,

I am trying to move a panel (panel2) around which is inside another
panel (panel1). I want the user to be able to use the arrow keys on the
keyboard.

However when I press either arrow key, focus is set to my toolbar
(toolbar1) and you see focus going from pushbutton to pushbutton.

I've tried keydown events on mybase, panel1, panel2 and finally only
this is working:

Private Sub ToolBar1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ToolBar1.KeyDown

If e.KeyCode = Keys.Right Then

panel2.location = [etc]

End If

End Sub

However this is not a nice workaround. If the user presses right or
left several times in a row or holds down the key, you see the panel
moving alright but also the toolbar gets repainted over and over again
to a point it can't repaint quickly enough and disappears a moment.

So both the panel is moving and the focus is moving over the
pushbuttons on the toolbar.

Can someone tell me how to tell the toolbar _not_ to catch keydown
events and let the panel1, panel2 or mybase or even the form handle
this (where it should be in this situation).

Help is appreciated!

Kind Regards,
Martin.
Dec 7 '06 #2

P: n/a
Once you've figured out where to put the statue I'm creating for you,
just say so!

In other words: thanks! works wonderfully !

Sugan wrote:
Use the following code in your form to handle the keypress event.

Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Right Then
'Move the Panel
Return True
End If
Return MyBase.ProcessDialogKey(keyData)
End Function

Hope this helps.

Sugan.

ma*****@hotmail.com wrote:
Dear group,

I am trying to move a panel (panel2) around which is inside another
panel (panel1). I want the user to be able to use the arrow keys on the
keyboard.

However when I press either arrow key, focus is set to my toolbar
(toolbar1) and you see focus going from pushbutton to pushbutton.

I've tried keydown events on mybase, panel1, panel2 and finally only
this is working:

Private Sub ToolBar1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ToolBar1.KeyDown

If e.KeyCode = Keys.Right Then

panel2.location = [etc]

End If

End Sub

However this is not a nice workaround. If the user presses right or
left several times in a row or holds down the key, you see the panel
moving alright but also the toolbar gets repainted over and over again
to a point it can't repaint quickly enough and disappears a moment.

So both the panel is moving and the focus is moving over the
pushbuttons on the toolbar.

Can someone tell me how to tell the toolbar _not_ to catch keydown
events and let the panel1, panel2 or mybase or even the form handle
this (where it should be in this situation).

Help is appreciated!

Kind Regards,
Martin.
Dec 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.