2017-06-20 14 views
0

数千行のコードと多くのボタンに相当するプログラムを作成しました。私は今、別のボタンからこのコードをシミュレートしたいと思います。私は、私がやりたいことをシミュレートするために、以下の小さなプログラムを書いています。私は他の例を見てきましたが、それは非常に簡単ですが、HOWと同じように見えます!マウス/ボタンをシミュレートする方法#をクリックしてください。

Button1.PerformClick(); 

しかし、ボタンのクリックをシミュレートする方法はありますか?

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

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

     private void button3_Click(object sender, EventArgs e) 
     { 
      //Some simulation code clcick button 2/3 
      //Button1.PerformClick(); 
     } 

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

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

マウスクリックイベントをシミュレートするか、イベントクリックイベントハンドラだけを実行しますか? – Alexander

+0

マウスクリックをシミュレートしますか?はい、私は思いますか?私はコードを再利用するのではなく、1千の行から5つのトーンまで実行したいと思います。これは実行時のplsです – Data

+1

'button1'はどこから来たのですか?タイプミスがありましたか?あなたのdesigner.csのコードとして表示 –

答えて

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(); 
    }  
} 
関連する問題