Solved

Multiple Forms

Posted on 2004-09-27
8
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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