469,602 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Keydown event problem

win
when the cursor is in a textbox, only coding in the keydown event of the
textbox triggered, the coding in the keydown event of the form does not
triggered!
Problem: I need to change a VB6 program to .Net. It uses function key(e.g.
F12) to close the form, now i need to write the coding in the keydown event
of all controls form.

Can anyone help me?
Thanks a lot.
Jan 4 '08 #1
3 4011
Hi Win,

You need to set the KeyPreview property of the form to true, which
indicates that the form will receive key events before the event is passed
to the control that has focus.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 7 '08 #2
Hi Win,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Jan 9 '08 #3
On Jan 4, 10:42 am, "win" <a...@a.comwrote:
when the cursor is in a textbox, only coding in the keydown event of the
textbox triggered, the coding in the keydown event of the form does not
triggered!
Problem: I need to change a VB6 program to .Net. It uses function key(e.g.
F12) to close the form, now i need to write the coding in the keydown event
of all controls form.

Can anyone help me?
Thanks a lot.
Hi,
If you want to close the form with a keypress having with several
controls on the form:
First set "KeyPreview" value to "true" in form properties.
Then simpy associate keydown event with form:

'Here is key for F12, you can change it whatever you want:

Private Sub Form1_keydown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.F12 Then
Me.Close()
End If

Hope this helps.

Thanks.
Jan 9 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by mee-shell | last post: by
4 posts views Thread by Mike M | last post: by
3 posts views Thread by bardo | last post: by
4 posts views Thread by Anne | last post: by
2 posts views Thread by Will Gillen | last post: by
1 post views Thread by fripper | last post: by
3 posts views Thread by MLM450 | last post: by
14 posts views Thread by raylopez99 | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.