新しいフォームを作成する方法によって異なります。チェックしてくださいthis 2つのシナリオが含まれています。
子フォーム:
public partial class Child : Form
{
public event NotifyParentHandler NotifyParent;
public delegate void NotifyParentHandler(string textValue);
public Child()
{
InitializeComponent();
}
private void btnNotify_Click(object sender, EventArgs e)
{
//assuming that you want to send the value when clicking a button
if (this.NotifyParent != null)
{
this.NotifyParent(textBox1.Text);
}
}
}
親フォームは
public partial class Parent : Form
{
private Child childForm;
public Parent()
{
InitializeComponent();
}
private void btnOpenChildForm_Click(object sender, EventArgs e)
{
// Open the child form
childForm = new Child();
childForm.NotifyParent += childForm_NotificationTriggered;
childForm.ShowDialog();
}
void childForm_NotificationTriggered(string textValuePassed)
{
//here you can do anything
}
}
は、それが完全に働いた、どうもありがとうございます! あなたはちょうど私がそれについてもっと読むことができるようにしたことを教えてもらえますか? もう一度ありがとうございます。 – gpenner