Solved

Multiple Forms

Posted on 2004-09-27
8
196 Views
Last Modified: 2010-04-15
I have 2 forms.  Form1 and Form2.  When the program starts, I want Form1 to be displayed.  When a button is pressed, I want Form1 to disappear and Form2 to be visible.  What is the button_click code to make this happen?  I am used to VB...  Form1.Visible = false, Form2.Visible = true etc :)

Thanks,
Tony
0
Comment
Question by:fattumsdad
  • 4
  • 3
8 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 12162798
Are you going to use Form1 again?  Or if you do, will it be a 'new' Form1?
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12162855
try form1.hide=true;
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 12162863
Since your application is probably using,

  Application.Run(new Form1());

The most simple code is:

  Hide();
  new Form2().Show();
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12162942
eternal,

I'll be switching between both forms.  I am using Application.Run(new MainForm());  The second form I'm using is frmAdmin...  I tried Hide(); frmAdmin().Show() to no avail :(  Also tried MainForm.hide = true...  
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:fattumsdad
ID: 12162999
I added:

this.visible = false;

And that will hide Form1...  now I just have to get Form2 open LOL
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 500 total points
ID: 12163052
Okay, IN YOUR MAIN FORM change:

  public MainForm()
  {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
  }

to:

  public frmAdmin AdminForm;

  public MainForm()
  {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    AdminForm = new frmAdmin(this);
  }

  private void SwitchToAdminForm()
  {
    AdminForm.Show();
    Hide();
  }


AND IN YOUR ADMIN FORM, change:

  public frmAdmin()
  {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
  }

to:

  MainForm mainForm;

  public frmAdmin(MainForm mainForm)
  {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    this.mainForm = mainForm;
  }

  public void SwitchToMain()
  {
    mainForm.Show();
    Hide();
  }


And then in your buttons, or whatever you can call the respective SwitchToMain, and SwitchToAdmin methods!
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 12163071
Sorry, I meant to explicitly declare,

  public frmAdmin AdminForm
  private void SwitchToAdminForm()
  MainForm mainForm;
  public void SwitchToMain()

all as Private, so if you want to change them they should look like:

  private frmAdmin AdminForm
  private void SwitchToAdminForm()
  private MainForm mainForm;
  private void SwitchToMain()

(Just like to keep the code consistent, will not affect operation - you can always make them public/internal later if you have a need).
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12163234
Right on!  Thanks a lot (again)!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now