textbox vs form keypress event

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
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
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
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.
 
Top Bottom