J
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
}
}
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
}
}