Reputation: 65
I want to click button from form 2 and button from form 1 at the same time.
If anyone can please suggest any ideas for this, it would be very helpful. Thanks in advance!
This my code
Form 2
public partial class Form2 : Form
{
Form1 ths;
public Form2(Form1 frm)
{
InitializeComponent();
ths = frm;
button1.Click += new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
ths.button1_2= button1;
}
}
Form 1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
new Form2(this).Show();
}
private void button1_2_Click(object sender, EventArgs e)
{
MessageBox.Show("Dot Net Perls is awesome.");
}
}
I think problem at this line ths.button1_2= button1;
because I modify from
ths.textBox1.Text = textBox1_2.Text;
but I don't know how to solve it.
Upvotes: 1
Views: 3912
Reputation: 63317
I think you want this:
private void button1_Click(object sender, EventArgs e)
{
ths.button1_2.PerformClick();
}
NOTE: It may solve your problem but in fact we don't do such a thing, we can always define some event, delegate or method to call directly rather via the programmatic clicking.
Upvotes: 5