How to prevent keydown events on toolbar

M

mart_nl

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.
 
S

Sugan

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.
 
M

mart_nl

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

In other words: thanks! works wonderfully !
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top