Solved

Multiple Forms

Posted on 2004-09-27
8
200 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
transaction in asp.net, sql server 6 46
how to remove duplicate code from my project 5 47
JQuery Detecting page post back 6 19
Return array 3 19
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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