I have 2 buttons. I am trying to use event from button 1 into button 2 so they both do the same thing.
So by clicking 2, button 1 get clicked also. I am doing this actually from menu strip item but I suppose it has the same principle. I just don’t want to have duplicated code. I thought that button1.Click() would work, but apparently it doesn’t. How could I do this?
Simplified example:
private void button1_Click(object sender, EventArgs e)
{
count += 1;
label1.Text = Convert.ToString(count);
}
private void button2_Click(object sender, EventArgs e)
{
count += 1;
label1.Text = Convert.ToString(count);
}
— EDIT —
I am using a class diagram which doesn’t show any additional methods that would/should do this. Need to stick to the class diagram.
You have a few options.
button2_Clickfrombutton1_click(i advise against this one).1
2
3