Call event handler programatically

M

mg

How can I call an event handler (e.g., Button1_Click)
programmatically. That is, without having to click on the
button with the mouse.
 
F

Frank Oquendo

mg said:
How can I call an event handler (e.g., Button1_Click)
programmatically. That is, without having to click on the
button with the mouse.

It's just a method like any other. So long as you pass the correct
number and type of parameters, you're free to call it any time you like.

Personally, I tend to code such that my event handlers pass their
arguments to a different routine. I do so for just this sort of
situation.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
M

mg

I've tried Button1_Click(null, null) and a few other
arguments when calling Button1_Click from within some
other method in the code behind ... but can't get the "do
something here" code to run. Can you give me something
more specific on how the Button1_Click method can be
called?


private void Button1_Click(object sender,
System.EventArgs e)
{
// do something here
}

Thanks!
 
M

mg

I've misrepresented my problem :-(

I'll now post a new message with a restatement of the
problem.
 
O

Onur Gorur

MG,

If you want to raise the event programatically use

RaiseEvent(button1.click) function!. (refer help on use :)

if you want to add a function in run time then use

addhandler a.click, addressof b

where a is control, b is your handler function

Onur
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top