2013-09-03 3 views
3

나는 이미 설계된 mdichild 양식을 가지고 있으며 양식을 mdichild로 표시하고자합니다. mdi에 기본 폼을 설정하고 폼 중 하나를 올바르게 mdichild로 표시 할 수 있습니다. 나에게 번거 로움을주고있다 코드는 다음과 같습니다 (아니지만 mdichild 등) this.MdiParent = _mForm;를 양식이 표시됩니다 :mdichild 양식이 표시되지 않습니다.

public partial class KeyboardSettingsForm : Form 
    { 
     private mainForm _mForm; 

     public KeyboardSettingsForm() 
     { 
      InitializeComponent(); 
      _mForm = new mainForm(); //<---mdiparent 
      this.MdiParent = _mForm; //<---Commenting out this line shows the form 

      this.Shown += new System.EventHandler(this.KeyboardSettingsForm_Shown); 

     } 
    } 

내가 주석 경우 이유를 모르겠습니다. 해당 코드는 그대로두고 양식을 표시하지 않습니다. 이 양식을 mdichild로 표시하려면 어떻게해야합니까?

mForm.IsMdiContainer = true; 
+0

제목을 편집했습니다. "[제목에"태그 "가 포함되어 있어야합니까?] (http://meta.stackexchange.com/questions/19190/)"합의가 "아니오, 그렇지 않아야합니다"로 표시되어야합니다. –

답변

2

당신은 mForm에게 MDI 컨테이너를 만들 필요가

_mForm = new mainForm(); 
this.MdiParent = _mForm; 

this.Shown += this.KeyboardSettingsForm_Shown; 

_mForm.Show(); // show mdi-parent explicitly because only the application's start-up form shows automatically. 
+0

_mForm이 실제 mdicontainer이고 MessageBox 출력이 True인지 테스트하기 위해 MessageBox.show (_mForm.IsMdiContainer.ToString());)를 수행했습니다. 그러나 여전히 폼을 표시하지 않은'_mForm.IsMdiContainer = true; '를 테스트했습니다. – dottedquad

+0

_mForm.Show() 후에도 @not가 아닌가? –

+0

'_mForm.Show()'는 이제 표시된 mdiparent mForm에만있는 KeyboardSettingsForm으로 다른 mdiparent를 엽니 다. – dottedquad

1

당신은 다음과 같이 명시 적으로 기본 폼을 표시해야합니다 :

업데이트 작업 코드

public partial class mainForm : Form 
{ 
    private NavigationForm _navForm; 
    public mainForm() 
    { 
     InitializeComponent(); 


     this.Shown += new System.EventHandler(this.mainForm_Shown); 

    } 

    private void mainForm_Shown(object sender, EventArgs e) 
    { 
     _navForm = new NavigationForm(this); 
     _navForm.MdiParent = this; 
     _navForm.Show(); 
    } 

    private void mainForm_Load(object sender, EventArgs e) 
    { 

    } 

} 

public partial class NavigationForm : Form 
{ 

    private KeyboardSettingsForm _wKeyboard; 

    public NavigationForm(Form frm) 
    { 
     InitializeComponent(); 

     _wKeyboard = new KeyboardSettingsForm(frm); 


    } 

    private void NavigationForm_Load(object sender, EventArgs e) 
    { 

    } 

    private void keyboardPictureBox_Click(object sender, EventArgs e) 
    { 
     _wKeyboard.Show(); 

    } 

} 

public partial class KeyboardSettingsForm : Form 
{ 
    private Form _mdiParent; 

    public KeyboardSettingsForm(Form frm) 
    { 
     InitializeComponent(); 
     _mdiParent = frm; 
     this.MdiParent = frm; 

     this.Shown += new System.EventHandler(this.KeyboardSettingsForm_Shown); 

    } 

    private void KeyboardSettingsForm_Load(object sender, EventArgs e) 
    { 
     MessageBox.Show(_mdiParent.Name); 
    } 

    private void KeyboardSettingsForm_Shown(object sender, EventArgs e) 
    { 

    } 
} 
1

당신은 말하고 있습니다. KeyboardSettingsForm 님의 부모는 누구입니까?하지만 부모를 보여주는 위치는 누구입니까?

_mForm = new mainForm(); //<---mdiparent not shown :(
this.MdiParent = _mForm; 

_mForm = new mainForm(); 
_mForm.Show();//show your parent first 
this.MdiParent = _mForm; 

그러나 심지어 위의 코드가 너무에만 적은 의미가보십시오. 이런 식으로하는거야?

public partial class KeyboardSettingsForm : Form 
{ 
    private mainForm _mForm; 

    public KeyboardSettingsForm(mainForm mForm) 
    { 
     InitializeComponent(); 
     this._mForm = mForm;//Did you mean this? 
     this.MdiParent = _mForm; 

     this.Shown += new System.EventHandler(this.KeyboardSettingsForm_Shown); 

    } 
}