Why windowstates are relative to each other?

46 Views Asked by At


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();
    }
}
0

There are 0 best solutions below