textbox vs form keypress event

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
if you have coded the form's keypress event (obviously the keypreview is true) does that override a textbox's keypress event (when textbox has focus) ? yea i'm not @ home right now... me.hasbeer = true
 
It doesn't override it but it does supersede it (the form's keypress event occurs first).

Both procedures will receive the same KeyPressEventArgs, so if you set the KeyPressEventArgs.Handled property to true in the form's keyPress event handler (e.Handled = True), the TextBox's keyPress event won't occur. Of course, the user won't be able to type anything in the textBox if the keyPress event doesn't occur.
 
Back
Top