Windows Develop Bookmark and Share   
 index > Windows Forms General > KeyPress event doesn't work
 

KeyPress event doesn't work

Hi, i have a problem with the KeyPress event, it just doesn't seem to work, i debuged the event and when it exits the sub with e.Handled = False it still let the chars in the textbox. I've tried to set KeyPreview property of the Form to True, but it still doesn't work. Thanks!
    Private Sub txtIP_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtIP.KeyPress
        If (Microsoft.VisualBasic.Asc(e.KeyChar) < 58 _
        And Microsoft.VisualBasic.Asc(e.KeyChar) > 47) Or _
        (Microsoft.VisualBasic.Asc(e.KeyChar) = 46) Then
            e.Handled = True
        Else
            e.Handled = False
        End If
    End Sub

Starterx  Sunday, October 04, 2009 7:15 AM
 it exits the sub with e.Handled = False it still let the chars in the textbox. <-- You should set e.handled=true to achieve this goal.
  • Marked As Answer byStarterx Sunday, October 04, 2009 7:58 AM
  •  
Tamer Oz  Sunday, October 04, 2009 7:44 AM
 it exits the sub with e.Handled = False it still let the chars in the textbox. <-- You should set e.handled=true to achieve this goal.
  • Marked As Answer byStarterx Sunday, October 04, 2009 7:58 AM
  •  
Tamer Oz  Sunday, October 04, 2009 7:44 AM
Thanks!
Starterx  Sunday, October 04, 2009 7:58 AM

You can use google to search for other answers

Custom Search

More Threads

• Copy/Paste??
• *GDI+* Change the DPI?
• MSFlexgrd unicode problem
• prevent clicking on the datagridview backgound
• Printer Margins Changes When Locale Changes
• PointToScreen off when child form goes to normal state
• Displaying Images In StatusStrip
• Put a glass panel over form while processing?
• Dynamic update of listview causes annoying blinking... how do you prevent this?
• MDI parent background?