Call event

J

John Wels

Hi.
How can I call some event in my code.
Example:
I have declared

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btntest.Click

'Code

End Sub



and in other place in code I want call event Button1_click.

How can I do IT?

Thanks for answers.
 
M

Marina

You can just call the method. It is just a regular method after all.

Since you will have to supply the arguments (which often time aren't even
used), many people place the code in the handler into a separate method, and
have the handler just call this method. This other method can then be called
from elsewhere without having to worry about suplly the sender and e
arguments.
 
P

Pipo

John Wels,

You could do something like this:

Button1_Click(Button1, System.EventArgs.Empty)
or make a seperate procedure in your button1_Click.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


OtherSubDoSomething

end sub

private sub OtherSubDoSomething

'code

end sub
 
H

Herfried K. Wagner [MVP]

John,

John Wels said:
How can I call some event in my code.
[...]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As [...]
and in other place in code I want call event Button1_click.

If the button is visible and enabled, you can call its 'PerformClick'
method. Alterantively you can take the code from the event handler and put
it into a separate procedure. This procedure can be called from within the
event handler and other procedures. If you really want to call the button's
'Click' event handler for some reason, you can pass 'EventArgs.Empty' in the
'e' parameter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top