2 Replies - 229 Views - Last Post: 06 February 2012 - 06:14 AM Rate Topic: -----

Topic Sponsor:

#1 FatalTouch  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 07-October 11

Showing a previously hidden form

Posted 05 February 2012 - 03:58 AM

Hello All,

The Problem i am facing now is that i created a Basic Login form and hided the form if the ID and Password are correct
and showed the main control panel.
But when i close that control panel the process didn't ended so i showed the Login form but it doesn't show the same instance of the form that i hided before..
so how am i supposed to show the previously hidden Instance of Login Form From my Main Form.?

Code for Login Form
MessageBox.Show("Valid","Message");
                frmMain form = new frmMain();
                form.User = User1;
                form.Show();
                this.Hide();



Code for Main Form
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {

            frmLogin form = new frmLogin();
            form.Show();
}



Is This A Good Question/Topic? 0
  • +

Replies To: Showing a previously hidden form

#2 RexGrammer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 152
  • View blog
  • Posts: 664
  • Joined: 27-October 11

Re: Showing a previously hidden form

Posted 05 February 2012 - 04:41 AM

The problem is: you aren't talking about the same form.

You create a new form and show it instead of showing the old one. That way the old one is always going to be hidden while you just create and show new ones.

A possible solution (I'm not sure that this is the right way to do it) is to pass a pointer to the original form in the second ones constructor. That way you can always show the main form, because you have a pointer pointing to it.
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1451
  • View blog
  • Posts: 5,763
  • Joined: 21-March 08

Re: Showing a previously hidden form

Posted 06 February 2012 - 06:14 AM

You can always get the current instance of a running(or hidden) form by using this code...

frmLogin loginForm = Application.OpenForms["frmLogin"] as frmLogin


Was This Post Helpful? 3
  • +
  • -

Page 1 of 1