MDI Problem

  • Thread starter Thread starter Ferryandi
  • Start date Start date
F

Ferryandi

Hi i want to ask question;

when i perform this function:

private void menuItem1_Click(object sender,
System.EventArgs e)
{
if(ActiveMdiChild.IsAccessible == true)
{
MessageBox.Show(ActiveMdiChild.Text);
}
}

It works when the form child is open, but when the form
child is not open it shows error like this:

An unhandled exception of
type 'System.NullReferenceException' occurred in
TestSystem.exe

Additional information: Object reference not set to an
instance of an object.

So how do i handle this excepetion.
 
Ferryandi,

Can you not test to see if the child is open by obtaining a reference to the
child? Then if the child == null do not execute the code. See the example
below.


Hope this helps.


----------------------

private void menuItem1_Click(object sender, System.EventArgs e)
{
Form tempChild = this.ActiveMdiChild;
if(tempChild != null)
{
if(tempChild.IsAccessible == true)
{
MessageBox.Show(tempChild.Text);
}
}
}
 
Back
Top