Article View: borland.public.csharpbuilder.language.csharp
Article #447Re: Problem with closing an MDI Child Windows
From: Marc Rohloff TeamB
Date: Tue, 25 Oct 2005 00:17
Date: Tue, 25 Oct 2005 00:17
42 lines
2414 bytes
2414 bytes
On 24 Oct 2005 09:03:04 -0700, Peter Jone wrote:
> 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.
How about:
> //Event when click the NewChild Menu item
> private void miNewChild_Click(object sender, System.EventArgs e)
> {
> frmChild objfrmChild = GetfrmChildInstance();
> 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();
> this.g_objfrmChild.MdiParent = this;
> this.g_objfrmChild.Show();
> }
>
> return this.g_objfrmChild;
> }
You should probably avoid the global variable and just use the
MdiChildren and ActiveMdiChild property of the form, i.e. just use
ActiveMdiChild.Close();
--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Technical Details
Message-ID:
<1dhje2fm97vwb.dlg@marcrohloff.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.inode.at!reader.uucp.at!feeder02.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mailReferences:
<435d05b8$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,5065392821169b29 X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Marc Rohloff [TeamB]" <"on request"> Subject: Re: Problem with closing an MDI Child Windows Newsgroups: borland.public.csharpbuilder.language.csharp User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit References: <435d05b8$1@newsgroups.borland.com> Date: Mon, 24 Oct 2005 20:17:24 -0400 Message-ID: <1dhje2fm97vwb.dlg@marcrohloff.com> X-Face: "huzh55Xi]!ZNni78>a*5+).`SK?<^q2MlHk-C]Z2M9T@\J5ZCB$95Ey+s"XQuhGFA[eutZ :0^AV!Q;t>gE`1-=8d;HZ6~*o1dH<X9\b$!|(}+I'!Xq)@3Op}%0ArW&nf'Qh*EwR X-Antivirus: avast! (VPS 0543-0, 10/24/2005), Outbound message X-Antivirus-Status: Clean NNTP-Posting-Host: 65.31.9.204 X-Trace: newsgroups.borland.com 1130198983 65.31.9.204 (24 Oct 2005 17:09:43 -0700) Lines: 42 X-Authenticated-User: mrohloff Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.inode.at!reader.uucp.at!feeder02.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail