如何模拟鼠标/按钮单击c#

时间:2017-06-20 04:13:34

标签: c# button click simulate

我写了一个程序,相当于几千行代码和许多按钮。我现在希望从另一个Button模拟这个代码。我在下面写了一个较小的程序来模拟我想做的事情。我看过其他的例子,看起来好像很简单,但是如何做!

class Calculation implements Runnable {
   ...
   @override 
   public void run() {
      // the name you passed to the thread is your math 
      // lets get it from the currently running thread where it is stored.         
      final String math = Thread.currentThread().getName();
      ...
   }

}

// somewhere else 
new Thread(new CalculationThread, math).start(); 

不会编译,但如何模拟按钮点击?

Button1.PerformClick();

1 个答案:

答案 0 :(得分:1)

我认为你拼错了。它应该是button3而不是Button3。相同的代码对我有用:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

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

    private void button2_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Button2.Clicked");
    }

    private void button3_Click(object sender, EventArgs e)
    {
        button1.PerformClick();
    }      
}
相关问题