473,466 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help! I can't find my child

Jon
I am writing an MDI app that uses a document manager class
to keep track of opened child windows. I want the user to
be able to close a child window, but then re-open the
window from the "Window" menu if they want.

What happens to the child window after it is closed? Even
though my document manager maintains the instance of the
child and displays the name in the menu, when I try to use
the show() method or the activate() method on a closed
child, nothing happens.

Can anyone help me with this?

Some of the code is below:

In the load event handler for the child, I register the
child with the following code-

DocumentManager.Current.RegisterDocumentView(this) ;
Here is the DocumentManager Class:

public class DocumentManager
{
public DocumentManager()
{}

private static DocumentManager current;
private ArrayList documents = new ArrayList();

public static DocumentManager Current
{get{return current;}}
public ArrayList Documents
{get{return documents;}}

[STAThread()] static void Main()
{
current = new DocumentManager();
///instantiate the parent window
PunchDocumentView view = new PunchDocumentView();
view.Show();
Application.Run();

public void RegisterDocumentView (frmChild view)
{
Documents.Add(view);
}
}

The popup event handler for the parent window creates the
menu with all documents currently in the manager:

private void menuWindow_Popup(object sender,
System.EventArgs e)
{
menuWindow.MenuItems.Clear();
int ordinal = 1;
foreach (frmChild view in
DocumentManager.Current.Documents)
{
WindowMenuItem item = new WindowMenuItem();
menuWindow.Menuitems.Add(item);
ordinal++;

And finally the WindowMenuItem class constructs the items
to be displayed in the menu. The overridden OnClick event
handler is where I am trying to display the closed form,
but it isn't working:

public class WindowMenuItem : System.Windows.Forms.MenuItem
{
public frmChild View;

public WindowMenuItem(int index, frmChild view)
{
View = view;
Text = string.Format("{0}{1}", index, View.Text)
}

protected override void OnClick(System.EventArgs e)
{
View.Show(); ///These 2 methods don't appear
View.Activate(); ///to do anything if the child
///is closed
}

}

Nov 15 '05 #1
2 1620
Once a child window is closed it's disposed of. If you maintain a reference
to it it will just prevent the garbage collector from finalizing it.

If you want to re-show an MDI child window, or indeed any form, don't close
it, hide it

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Jon" <jh******@netzero.net> wrote in message
news:0b****************************@phx.gbl...
I am writing an MDI app that uses a document manager class
to keep track of opened child windows. I want the user to
be able to close a child window, but then re-open the
window from the "Window" menu if they want.

What happens to the child window after it is closed? Even
though my document manager maintains the instance of the
child and displays the name in the menu, when I try to use
the show() method or the activate() method on a closed
child, nothing happens.

Can anyone help me with this?

Some of the code is below:

In the load event handler for the child, I register the
child with the following code-

DocumentManager.Current.RegisterDocumentView(this) ;
Here is the DocumentManager Class:

public class DocumentManager
{
public DocumentManager()
{}

private static DocumentManager current;
private ArrayList documents = new ArrayList();

public static DocumentManager Current
{get{return current;}}
public ArrayList Documents
{get{return documents;}}

[STAThread()] static void Main()
{
current = new DocumentManager();
///instantiate the parent window
PunchDocumentView view = new PunchDocumentView();
view.Show();
Application.Run();

public void RegisterDocumentView (frmChild view)
{
Documents.Add(view);
}
}

The popup event handler for the parent window creates the
menu with all documents currently in the manager:

private void menuWindow_Popup(object sender,
System.EventArgs e)
{
menuWindow.MenuItems.Clear();
int ordinal = 1;
foreach (frmChild view in
DocumentManager.Current.Documents)
{
WindowMenuItem item = new WindowMenuItem();
menuWindow.Menuitems.Add(item);
ordinal++;

And finally the WindowMenuItem class constructs the items
to be displayed in the menu. The overridden OnClick event
handler is where I am trying to display the closed form,
but it isn't working:

public class WindowMenuItem : System.Windows.Forms.MenuItem
{
public frmChild View;

public WindowMenuItem(int index, frmChild view)
{
View = view;
Text = string.Format("{0}{1}", index, View.Text)
}

protected override void OnClick(System.EventArgs e)
{
View.Show(); ///These 2 methods don't appear
View.Activate(); ///to do anything if the child
///is closed
}

}

Nov 15 '05 #2
Just thinking out loud here...

Trap the closing event.hide the window and cancel the close.

Hmm that might have implications for when you really want to close.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Jon" <jh******@netzero.net> wrote in message
news:09****************************@phx.gbl...
Bob,

Thanks for your input, but how can I prevent the user from
closing the window?

Thanks again for your help.

Jon

-----Original Message-----
Once a child window is closed it's disposed of. If you

maintain a reference
to it it will just prevent the garbage collector from

finalizing it.

If you want to re-show an MDI child window, or indeed any

form, don't close
it, hide it

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Jon" <jh******@netzero.net> wrote in message
news:0b****************************@phx.gbl...
I am writing an MDI app that uses a document manager class to keep track of opened child windows. I want the user to be able to close a child window, but then re-open the
window from the "Window" menu if they want.

What happens to the child window after it is closed? Even though my document manager maintains the instance of the
child and displays the name in the menu, when I try to use the show() method or the activate() method on a closed
child, nothing happens.

Can anyone help me with this?

Some of the code is below:

In the load event handler for the child, I register the
child with the following code-

DocumentManager.Current.RegisterDocumentView(this) ;
Here is the DocumentManager Class:

public class DocumentManager
{
public DocumentManager()
{}

private static DocumentManager current;
private ArrayList documents = new ArrayList();

public static DocumentManager Current
{get{return current;}}
public ArrayList Documents
{get{return documents;}}

[STAThread()] static void Main()
{
current = new DocumentManager();
///instantiate the parent window
PunchDocumentView view = new PunchDocumentView (); view.Show();
Application.Run();

public void RegisterDocumentView (frmChild view)
{
Documents.Add(view);
}
}

The popup event handler for the parent window creates the menu with all documents currently in the manager:

private void menuWindow_Popup(object sender,
System.EventArgs e)
{
menuWindow.MenuItems.Clear();
int ordinal = 1;
foreach (frmChild view in
DocumentManager.Current.Documents)
{
WindowMenuItem item = new WindowMenuItem();
menuWindow.Menuitems.Add(item);
ordinal++;

And finally the WindowMenuItem class constructs the items to be displayed in the menu. The overridden OnClick event handler is where I am trying to display the closed form,
but it isn't working:

public class WindowMenuItem : System.Windows.Forms.MenuItem {
public frmChild View;

public WindowMenuItem(int index, frmChild view)
{
View = view;
Text = string.Format("{0}{1}", index, View.Text)
}

protected override void OnClick(System.EventArgs e)
{
View.Show(); ///These 2 methods don't appear View.Activate(); ///to do anything if the child ///is closed
}

}

.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
11
by: Helmut Jarausch | last post by:
Hi, entering help('rstrip') or help('ljust') into IDLE's shell window I only get no Python documentation found ...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
1
by: Tim Marshall | last post by:
I'm putting together my first help file (using Easy Help, http://www.easyhelp.com/). So far, so good. I'm able to use the Help File and Help Context ID to have things from my help file pop up...
3
by: stuart_white_ | last post by:
I've just upgraded from Python 2.3.3 to Python 2.4.2, and, although the new version of Python seems to be running correctly, I can't seem access the help from the interpreter. On Python 2.3.3...
9
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
5
by: PaulS | last post by:
new to Fedora7, typed python in interactive interpreter, then help(). Then modules to get a list of modules. Then module name to get info on a module but no help file. What is the help file...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.