1

我想同时单击表单 2 中的按钮和表单 1 中的按钮。

如果有人可以为此提出任何想法,那将非常有帮助。提前致谢!

这是我的代码

表格 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;

    }
}

表格 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.");

    }
}

我认为这一行有问题,ths.button1_2= button1;因为我修改了 ths.textBox1.Text = textBox1_2.Text;但我不知道如何解决它。

4

1 回答 1

5

我想你想要这个:

private void button1_Click(object sender, EventArgs e)
{
    ths.button1_2.PerformClick();
}

注意:它可能会解决您的问题,但实际上我们不会这样做,我们总是可以定义一些事件、委托或方法直接调用,而不是通过程序化的点击。

于 2013-11-07T15:13:31.643 回答