0

I am doing some maintenance on a legacy winforms application. The project uses form inheritance which makes my job much easier, but there is a strange problem. The setup is as follows:
FormBase : Form
FormBaseList : FormBase
FormClientList : FormBaseList

The problem I have now is with the property WindowsState.
I create a new FormClientList.

    FormClientList f = new FormClientList();  
    f.MdiParent = this;
    f.show();

Than I click on the maximize button so it becomes maximized.
Now I have a button (for debug purpose) on FormClientList to show me the value of the property WindowState and it returns maximized, as I expected.

In FormBaseList there is some code that needs to know the value of this property, but here it always returns normal, not maximized. The code is on the doubleclick of a datagridview, which will create another form.

// code in FormBaseList
FormDetail detailForm = new FormDetail();
detailForm.MDIParent = this.MDIParent;
detailForm.Show();
if (this.WindowState == FormWindowState.Normal) // this = the maximized instance of FormClientList
{
    // why do I get here when FormClientList is maximized ??
    detailForm.Left = this.Left + 20;
    detailForm.Top = this.Top + 20;
}

So it seems that the instance of this form has different values for this propertie depending from which class I run my testcode ?

How do I fix this ?

GuidoG
  • 11,359
  • 6
  • 44
  • 79
  • This is a normal mishap, MDI overrides the window state of a child without telling you about it. Happens for example when you activate a child and the current child is maximized. The new active child will also be maximized, regardless of its WindowState value. You need to work around this. – Hans Passant Feb 05 '15 at 16:19
  • I already noticed that, but the question is why does the form has one value in a property and another value in that same property when examining the property in a parent class of the same instance. – GuidoG Feb 05 '15 at 16:23

0 Answers0