2017-11-18 8 views
0

質問があり、進行方法が不明で、指示を求めています。ユーザーコントロールにテキストボックステキストを送信

私は、Panel1を持つForm1を持っており、これらのユーザーコントロールのそれぞれに3つの異なるユーザーコントロールをPanel1(UserControl1、UserControl2およびUserControl3)内に読み込むことができます。

私が必要とするのは、Form2のボタンを押すたびに、TextBoxのすべてのテキストがForm2を開いたユーザーコントロールに送信されることです。

誰かが私に感謝することができれば、私の質問が明確かどうか分かりません。ありがとう、ありがとう。

答えて

0

新しいフォームを作成する方法によって異なります。チェックしてください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 
    } 
} 
+0

は、それが完全に働いた、どうもありがとうございます! あなたはちょうど私がそれについてもっと読むことができるようにしたことを教えてもらえますか? もう一度ありがとうございます。 – gpenner

関連する問題