Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling command button click event 1

Status
Not open for further replies.

stuartd

Programmer
Jan 8, 2001
146
US
Hi,

I have a button which when clicked runs some code.

I want to call the 'click' event when i load the form for the first time to run this code.

In vb i just said 'command1_click'.
The Click method in .Net requires arguments (object sender, System.EventArgs e) which i don't have.

Can i do this? or do i just move the code out of the event into another function?

SD
 
I think the button has a performclick method.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Take the code inside the click event function and put it into its own function. Then call this function whenever you need it.
 
This works, but I don't know if theres a more "proper" way, cos I'm a noob :D

protected override void OnLoad(System.EventArgs e)
{
...
}

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Christiaan has the right idea.

command1.PerformClick() will call the click event.

--Brad

"Life is too important to be taken seriously" --Albert Einstein
 
Could you enlighten me please Duncan, as I say I'm a confessed noob and all these things help :)

Thanks
//karv.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
command1_click(null, EventArgs.Empty) would also work. This method is a bit of a hack. Putting the functionality into its own method is the preferred option.
 
Ok - thanks guys. So we have :

1. command1.PerformClick();
2. command1_click(null, null);
3. command1_click(null, EventArgs.Empty);

I assume 1. would be the prefered option



SD
 
Jippie, he picked me.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Christiaan Baes,
This is not the first time you have had me sitting in my cube lol.
tyvm,
Marty
 
I do my best.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top