私のwinformでは、フォームのdesigner.csセクションにあります
this.Button1.Text = "&Click";
this.Button1.Click += new System.EventHandler(this.Button1_Click);
form.csで
private void Button1_Click(object sender, System.EventArgs e)
{
//Code goes here.
}
フォームの一部にツリービューがあり、そのツリービューのコンテンツが展開されたら、上記のボタンの名前を変更して、別のイベントを接続する必要があります
Button1.Name = "ButtonTest";
ButtonTest.Click += new System.EventHandler(this.ButtonTest_Click);
ただし、ButtonTestが見つからないと言って失敗します。ボタンの名前を動的に変更し、別のクリックイベントメソッドを呼び出すにはどうすればよいですか?
private void ButtonTest_Click(object sender, System.EventArgs e)
{
//Code goes here.
}
これがButtonTest_Clickと呼ばれると、名前をButton1に戻す必要があります。何か考えはありますか?