2017-09-23 7 views
0

MDI 부모 폼에서 자식 폼으로 값을 전달하는 방법에 대한 도움이 필요합니다. 부모님의 폼에는 MALE과 FEMALE이라는 두 개의 라디오 버튼이 있습니다.이 중 하나를 선택하고 버튼을 클릭하면 할당 된 값이 하위 폼으로 전송됩니다. 아래에있는 내 코드를 참조하십시오C# MDI 부모 폼에서 자식으로 값 전달

학부모 형태 :

private void ButtonSelect_Click(object sender, EventArgs e) 
     { 
      if (this.rbMale.Checked) 
      { 
       string gender= "MALE"; 
       frmChild childform = new frmChild(); 
       childform.GetGender = gender; 

       frmChild newMDIChild = new frmChild(); 
       newMDIChild.MdiParent = this; 
       newMDIChild.Show(); 

      } 

      else if (this.rbFemale.Checked) 
      { 
       string gender= "FEMALE"; 
       frmChild childform = new frmChild(); 
       childform.GetGender = gender; 

       frmChild newMDIChild = new frmChild(); 
       newMDIChild.MdiParent = this; 
       newMDIChild.Show(); 

      } 
    } 

자식 폼 : 나는 또한 일시적으로 정말 부모로부터 값을 가져 여부를 알려주는 메시지 박스를 넣어

public string GetGender { get; set; } 

private void frmChild_Load(object sender, EventArgs e) 
     { 
      if (GetGender == Convert.ToString("MALE")) 
      { 
       /*my code here*/ 
      } 
      else if (GetGender == Convert.ToString("FEMALE")) 
      { 
       /*my code here*/ 
      } 
     MessageBox.Show(GetGender); 
     } 

양식을 만들지 만 빈 상태 만 반환합니다.

는 또한 당신은 그것을 표시하기위한 성별을 할당하여 childForm의 두 인스턴스를 생성하고 다른 것 thisthis

답변

0

을 시도했다. 하나의 인스턴스 만 필요하면 if 문을 변경하십시오.

... 
if (this.rbMale.Checked) 
    { 
     string gender= "MALE";  
     frmChild newMDIChild = new frmChild(); 
     newMDIChild.GetGender = gender; 
     newMDIChild.MdiParent = this; 
     newMDIChild.Show(); 
    } 
... 
+0

감사합니다 !!! 나는 그것을 알아 차리지 못했다. 이제 나 자신을 비웃고있다. 다시 한 번 감사드립니다! – itsmePJ

관련 문제