0


I have 3 forms in my windows forms application.
1. is main form and it is mdiParent.
2. is a mdiChild form which will shown in maximised state.
3. is another mdiChild which will shown in normal state.

when I open form2 it will shown in maximised state but the problem is when I open form3 in same time the form3 is shown in maximised state too and when I change the state of form3 to normal state manually in runtime (restore the window) the form2 backs to normal state too. In other words: their states are relative to each other.
There is the part of code which opens the form3 inside of form2 codes.

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    string str = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
    string str3 = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
    var str2 = dataGridView1.SelectedRows[0].Cells[0].Value ;
    Forms.frmTrack frm = new frmTrack();
    frm.CustomerID = (int)str2;
    frm.CompanyName = str;
    frm.CustomerName = str3;
    Classes.Function fn = new Classes.Function();
    frm.WindowState = FormWindowState.Normal;
    fn.ShowForm(frm, this.MdiParent);
    frm.WindowState = FormWindowState.Normal;
}

and this is my ShowForm() function:

public void ShowForm(Form frmChild,Form frmParent)
{
    bool formFound = false;
    foreach (Form item in frmParent.MdiChildren)
    {
        if (item.Name == frmChild.Name)
        {
            item.Activate();

            formFound = true;
        }

    }
    if (!formFound)
    {
        frmChild.MdiParent = frmParent;
        frmChild.Show();
    }
}
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
Kia Boluki
  • 315
  • 3
  • 15
  • 2
    It's the way that MDI works. – Reza Aghaei Nov 14 '16 at 10:20
  • Probably part of the reason why nobody's been using that form of MDI for decades. – Frédéric Hamidi Nov 14 '16 at 10:26
  • what should I do to avoid this or what is the preferred approach? – Kia Boluki Nov 14 '16 at 10:28
  • I need each form opens in its state , one in maximise state and another in normal state . – Kia Boluki Nov 14 '16 at 10:36
  • do I should give up mdiForms completely ? – Kia Boluki Nov 14 '16 at 10:40
  • @mohammad, if you want to have two MDI children in different states (one maximised, the other restored), then yes, MDI forms won't do the trick. A tab-based UI won't either. Maybe you should make a mockup or two of your design and ask for advice on [ux.se]. – Frédéric Hamidi Nov 14 '16 at 10:42
  • The requirement would not seem so friendly to end users IMO. Users which are familiar with MDI probably prefer to work with MDI the way they used to work always. It's better to not surprise users. If for any reason you want to show a non-maximized window, don't add it as MDI Child, just show it without adding as MDI Child. Also as another option you can have a Docked panel in MDI parent to show some content which should be always visible, I consider it as a maximized window and then for other windows, just add them as MDI children as usual. – Reza Aghaei Nov 14 '16 at 11:06

0 Answers0