2017-11-18 2 views
0

질문이 있는데 진행 방법이 확실하지 않고 방향을 찾고 있습니다.사용자 컨트롤에 TextBox 텍스트 보내기

여기에 제 시나리오가 있는데, panel1이있는 Form1이 있고, Panel1 (UserControl1, UserControl2 및 UserControl3) 내부에 3 개의 다른 사용자 컨트롤을로드 할 수 있습니다. 이러한 각 사용자 컨트롤 안에는 몇 개의 TextBox가있는 Form2를 열 수 있습니다.

내가 필요한 것은 Form2에서 버튼을 눌렀을 때 모든 TextBox 텍스트가 Form2를 연 사용자 컨트롤로 전송된다는 것입니다.

내 질문에 분명하다면 누구나 고맙게 여기며 도와 주시면 감사하겠습니다. 감사합니다.

답변

0

새 양식을 만드는 방법에 따라 다릅니다. 확인하십시오 this 두 시나리오가 포함되어 있습니다.

자식 폼 :

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

관련 문제