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"

Hi,

Use:

Buttonname.PerformClick()

And what about parameter passing ?

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.

Hi,

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
    Button1.PerformClick()
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))
        Next
    End If

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.