C♯相談室 Part31
■ このスレッドは過去ログ倉庫に格納されています
0083デフォルトの名無しさん
2006/04/18(火) 01:26:40public delegate void TextUpdatedEventHandler(object sender, TextUpdatedEventArgs e);
public class TextUpdatedEventArgs : EventArgs {
public TextUpdatedEventArgs(string text) {
this.text = text;
}
private string text;
public string Text { get { return this.text; } }
}
public class Form1 : Form {
// 略
Form2 form2;
private void showButton_Click(object sender, EventArgs e) {
if (form2 == null || form2.IsDisposed) {
form2 = new Form2();
form2.TextUpdated += new TextUpdatedEventHandler(this.UpdateText);
}
form2.Show();
}
private void UpdateText(object sender, TextUpdatedEventArgs e) {
this.textBox1.Text = e.Text;
}
}
public class Form2 : Form {
// 略
public event TextUpdatedEventHandler TextUpdated;
private void updateButton_Click(object sender, EventArgs e) {
if (this.TextUpdated != null)
this.TextUpdated(this, new TextUpdatedEventArgs(this.textBox1.Text));
}
}
これで Form2 が Form1 を知っている必要が無くなる、
■ このスレッドは過去ログ倉庫に格納されています