Forms question

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi all,

I have an app using multiple forms a -> b-> c.

Form c is created from form b and shown and then form b immediately Hide's
itself (which I understand does not remove from memory). How can I then
simply re-show Form b from Form c?

Regards
John.
 
FormC must have a reference to the instance of FormB that you created in
FormA. Simply call Show on the instance.

-Chris
 
Chris,

Thanks for a timely response. Excuse my ignorance but could you please
possibly provide a code example? I have tried creating another overriding
constructor in form c and passing form b to it but can't seem to get it
working.

Regards
John.
 
Chris,

Thanks for a timely response. Excuse my ignorance but could you please
possibly provide a code example? I have tried creating another overriding
constructor in form c and passing form b to it but can't seem to get it
working.

Regards
John.
 
Hi John,

How to show/display the instance of the parent/calling form?

You could pass a reference of the parent/calling form to the child form
through a constructor. Then when you want to display the parent form, just
call show on the reference.

Here is some code to put in the sub form:

public class ShowParentForm : System.Windows.Forms.Form {

// Declare member variable to store reference to parent form.
private System.Windows.Forms.Form _parentForm;

// Set the parent form in the constructor.
public ShowParentForm(Form parentForm) {

InitializeComponent();

_parentForm = parentForm;

}

// Display the parent form.
private void button1_Click(object sender, System.EventArgs e) {

if (_parentForm != null) {
_parentForm.Show();
this.Close();
}

}

}

To call this:
ShowParentForm frm = new ShowParentForm(this);
frm.Show();

Hope that helps,
Tom


--
Tom Krueger
Microsoft Corporation
Program Manager
http://weblogs.asp.net/tom_krueger

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
Again, thanks a lot. I managed to get it working nicely (I set the
references both ways in the constructor).
 
Back
Top