Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1684
  • Last Modified:

On Button Click Load Windows Form

Its been a while sense I've used Visual Studio so bare with me.  What is the line of code that will load a new form when I click a button and run a check.  I would expect it to be Load.Form1.cs or something along those lines.  Thank you!
0
ReganJ03
Asked:
ReganJ03
1 Solution
 
Jai STech ArchCommented:

yourFormName frmObject = new yourFormName();
frmObject.ShowDialog(); // or frmObject.Show();
0
 
angus_young_acdcCommented:
Here is what it would look like in your button.

The last two (this.hide and this.close) are optional and don't need to be done unless you want to, and you should pick one or the other (not use both as in the example below).  Also if you use Close on your main form it will stop your application completely, so all other forms will close.
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 openForm = new Form2();
            openForm.Show();              // Opens the other form
           
            this.Hide();                // Hide the current form 
            this.Close();               // Closes the current form
        }

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now