Click here to Skip to main content
15,887,369 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ı want to call anywhere how can ı do?



private void button9_Click(object sender, EventArgs e)
{
...............
...............
}
Posted

Do you mean like this?
C#
button9_Click( null, EventArgs.Empty );


Nick
 
Share this answer
 
The same way you would call any function. Create an Object object and an EventArgs object and pass them to your function, e.g.
Object sender = new Object();
EventArgs e = new EventArgs();
button9_Click(sender, e);
 
Share this answer
 
As its a private function then you will only be able to call it inside one of the functions of the class that contains the buttonclick function.you can call it from any of the internal functions using the class object or object pointer("this" pointer).
 
Share this answer
 
Nick's answer will do what you want, but this might be better:
C#
public MeaningfulFunctionName()
{
  //Do stuf here
}


private void button9_Click(object sender, EventArgs e)
{ 
  MeaningfulFunctionName();
}


Better still: Abstract out an object model and put MeaningfulFunctionName in there. Doing this puts the functionality into unit testable code. If you have a more complex application (many screens) try looking for the MVP pattern on google.
 
Share this answer
 
v2
Hi,
Yes you can do this its very simple say u wana call button1 click function and u write some code in button1 click function say for example to display a message box, u would write something like this in ur button1's click event now we want to call button1's click event in button2 then just refer to code of button2 click event

CODE FOR BUTTON 1 CLICK EVENT

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("hello");
}

CODE FOR BUTTON 2 CLICK EVENT

private void button2_Click(object sender, EventArgs e)
{
button1_Click(sender, e); //calling button1's click event
}

do rate my answer once you find it useful
Thanks & Regards
Radix :rose:
 
Share this answer
 
Hello,
You Can Create A Event Of Any Button At Run Time Like
The button Name is btn then and creating a click event then..

btn.Click += new EventHandler(btn_Click);
void btn_Click(object sender, EventArgs e)


And For any Problem send a mail to nayan4fun@gmail.com
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900