私は次のコードを持っています:
private void someButton_Click(object sender, EventArgs e)
{
SomeForm f = new SomeForm();
this.SomeEvt += f.someFunc;
this.AnotherEvt += f.anotherFunc;
f.Show();
}
万一Iの登録解除 f.someFunc
からthis.SomeEvt
とf.anotherFunc
からthis.AnotherEvt
?
演奏したくf.anotherFunc
ないしsomeFunc
、f
閉まっているときも
そして、登録を解除する必要がある場合SomeForm f
、この関数の終了後にもう存在しないので、どうすればよいですか?
.Net Framework4.0とWinFormsを使用しています。
私のコメントに対するあなたの答えによると:
...閉まっている
f.anotherFunc
ときに演奏したくないf
ラムダなどを使用して、イベントの登録を解除する必要があります。
private void someButton_Click(object sender, EventArgs e)
{
SomeForm f = new SomeForm();
this.SomeEvt += f.someFunc;
this.AnotherEvt += f.anotherFunc;
f.FormClosed += (ss, ee) => {
this.SomeEvt -= f.someFunc;
this.AnotherEvt -= f.anotherFunc;
};
f.Show();
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加