Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multiple Forms

Posted on 2004-09-27
8
Medium Priority
?
203 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 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