This one's been an annoying thorn in my side...
I've developed a graphics based application on a userform with the GDI. I've set KeyPreview to True so I can add shortcut hotkeys to my app on the keydown event. So far so good...
I've built a "Nudge" tool that moves selected graphic shapes one pixel if the appropriate arrow key is pressed.
Even though I have KeyPreview set to true I'm having 2 problems with the arrow key nudge.
1) If I don't have a textbox on the userform, the arrowkeys are not detected regardless of the KeyPreview set to True.
2) Now that I do have a half-dozen or so textboxes on my userform, the arrowkeys are registering with the form as if I want to use them to advance between the textboxes. After 3 or 4 keypresses it seems to "break-thru" and my intended Nudge starts to work.
At the moment, I'm most interested in overcoming item number 2 above, as I hate the fact that I have to press the arrowkey repeatedly before my nudget is recognized. However, I'd also like to know the answer to item 1 because I may very well want to use the arrowkeys on a form in the future that does not contain textboxes.
Here's a snippet showing my arrow key assignments for the userform keydown event:
I thought by setting e.Handled to true I was prohibiting the userform textboxes from receiving the arrowkey?
I've developed a graphics based application on a userform with the GDI. I've set KeyPreview to True so I can add shortcut hotkeys to my app on the keydown event. So far so good...
I've built a "Nudge" tool that moves selected graphic shapes one pixel if the appropriate arrow key is pressed.
Even though I have KeyPreview set to true I'm having 2 problems with the arrow key nudge.
1) If I don't have a textbox on the userform, the arrowkeys are not detected regardless of the KeyPreview set to True.
2) Now that I do have a half-dozen or so textboxes on my userform, the arrowkeys are registering with the form as if I want to use them to advance between the textboxes. After 3 or 4 keypresses it seems to "break-thru" and my intended Nudge starts to work.
At the moment, I'm most interested in overcoming item number 2 above, as I hate the fact that I have to press the arrowkey repeatedly before my nudget is recognized. However, I'd also like to know the answer to item 1 because I may very well want to use the arrowkeys on a form in the future that does not contain textboxes.
Here's a snippet showing my arrow key assignments for the userform keydown event:
VB.NET:
Private Sub Frm_MoBo_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
' Sets Handled to true to prevent other controls from
' receiving the key if an arrow key was pressed
Select Case e.KeyCode
Case Keys.Right, Keys.Left, Keys.Up, Keys.Down
TxtArrowKeyEnable.Select()
Nudge(e.KeyCode)
e.Handled = True
I thought by setting e.Handled to true I was prohibiting the userform textboxes from receiving the arrowkey?
Last edited: