【问题标题】:How to click button from form 1 and button from another form already clicking如何单击表单 1 中的按钮和已经单击的另一个表单中的按钮
【发布时间】:2013-11-07 15:04:39
【问题描述】:

我想同时点击表单 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; 但不知道怎么解决。

【问题讨论】:

  • 让我看看我是否理解正确:你想点击Form2.Button1。当您这样做时,您是否也希望点击 Form1.Button1? (即你想打电话给Form1.Button1OnClick
  • I want to click button from form 2 and button from form 1 already clicking in the same time. 我不知道你在这里想说什么。

标签: c# winforms forms


【解决方案1】:

我想你想要这个:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    相关资源
    最近更新 更多