Log in

View Full Version : Is it possible to trigger KeyPress event manually?


albertkhor
12-08-2005, 12:02 PM
can anyone tell me is it possible to trigger KeyPress event manually?
if yes can tell me how?

What i want to do:
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox1.KeyPress
MakeAcceptDecimalOnly(e, textbox1.Text)
End Sub

above is my own code which is use to trigger user keypress and let the textbox accept integer only if user key in character the MakeAccpetDecimalOnly function will do nothing (i use e.Handled = True).
i want to create a button so when user click on the button, system will auto trigger the KeyPress and run the MakeAccpetDecimalOnly function. Ecample below:

Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
dim chracter as string = "a"
'how to triger keypress events manually
End Sub

so that character "a" will pass to textbox1 without user key in any character but just click on the button!