i want to call event procedures (button1_click etc.) on certain conditions

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = "A"  then 
     'here i don't know how to call button1_click procedure   
End If

here is what i want to do :-

whenever any character is inputted to textbox1 then it will call button1_click where i code to print ascii value of the character

ex:- if i input A to textbox1 then should print 65

so i dont know to how to call button1_click event procedure with parametes as "A"

Edited by Learner010

5 Years
Discussion Span
Last Post by Luc001

What about:

If e.KeyChar = "A"  then 
     'here i don't know how to call button1_click procedure  
     'do not call button click
     TextBox1.Text = "65";
     e.Handled = true;
End If

What parameters do you want to get passed to the button click handler that would not get passed if you just clicked the button? If you need to get at a value you could always set Button1.Tag to be the value before you do PerformClick, then clear the tag in the click handler at the end of processing.



Here's another way of doing it with the Textbox_Textchanged event:

   Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If Me.TextBox1.Text <> "" Then
        For Each ch As Char In Me.TextBox1.Text
            TextBox2.Text = CStr(Asc(ch))
    End If

End Sub

Edited by Luc001: Better coding

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.