Solved

Multiple Forms

Posted on 2004-09-27
8
195 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

13 Experts available now in Live!

Get 1:1 Help Now