🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #446

Problem with closing an MDI Child Windows

#446
From: Peter Jone
Date: Mon, 24 Oct 2005 16:03
47 lines
2080 bytes
Hi,

I have 2 WinForms for my MDI app. One is ParentForm; another is 
ChildForm. Below is part of my code in the ParentForm. What I 
am trying to do is that after clicking NewChild menu item, 
check if any Child instance is created. If so, bring the 
existing Child to front. If not, create a new Child instance. 
But the problem is when I click Close menu item to close the 
Child, it is never closed. 

*********************************
private frmChild g_objfrmChild;

//Event when click the NewChild Menu item
private void miNewChild_Click(object sender, System.EventArgs e)
{
  frmChild objfrmChild = GetfrmChildInstance();
  objfrmChild.MdiParent = this;
  objfrmChild.Show();
  objfrmChild.BringToFront();
}

//Check if any Child instance is created
public frmChild GetfrmChildInstance()
{
  if (this.g_objfrmChild == null)
  {
    //if not created yet, Create an instance
    this.g_objfrmChild = new frmChild();
  }

  return this.g_objfrmChild;
}

//Event when click Close menu item
private void miClose_Click(object sender, System.EventArgs e)
{
  if(this.ActiveMdiChild.Name == "frmChild")
  {
    this.g_objfrmChild.Close();
  }
}
*******************************************************

Thanks in advance,
Peter
Technical Details
Message-ID: <435d05b8$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,5065392821169b29,start
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Peter Jone" <peter@hotmail.com>
Sender: "Peter Jone" <peter@hotmail.com>
Reply-To: "Peter Jone" <peter@hotmail.com>
Subject: Problem with closing an MDI Child Windows
Newsgroups: borland.public.csharpbuilder.language.csharp
X-User-Info: 65.94.192.182     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <435d05b8$1@newsgroups.borland.com>
Date: 24 Oct 2005 09:03:04 -0700
X-Trace: newsgroups.borland.com 1130169784 207.105.83.66 (24 Oct 2005 09:03:04 -0700)
Lines: 47
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail