Page 1 of 1
Need a certain code
Posted: Sat Oct 04, 2008 9:08 am
by Eaton
Hi. I have been trying to make it so that a button is disabled when there are no open MDI windows. I know the code goes something like this, but I cannot figure out the right way to put it in.
if (Mdi.Children.Count = 0)
button2.Enabled = false;
Re: Need a certain code
Posted: Sat Oct 04, 2008 9:32 am
by LuxuriousMeat
Eaton wrote:Hi. I have been trying to make it so that a button is disabled when there are no open MDI windows. I know the code goes something like this, but I cannot figure out the right way to put it in.
if (Mdi.Children.Count = 0)
button2.Enabled = false;
Code: Select all
if (this.MdiChildren.Length < 1) button1.Enabled = false;
But if you want this to happen when the last child form closes you could use this code in the child forms 'FormClosed' event:
Code: Select all
this.Dispose();
MainFormType parent = (MainFormType)this.MdiParent;
if (parent.MdiChildren.Length < 1)
parent.MethodToDisableButton();
else
parent.MethodToEnableButton();
Or, to disable the button you could change the button's protection level to public and just disable it.