C # How to switch the window by clicking the button in winform

Source: Internet
Author: User

The implementation method is as follows:

1. Design first, put a panel on the left, put a panel on the right (named pnlmain), adjust the size, and place two buttons on the left panel (the same applies to multiple buttons)

2. Write the method in the button

Click the "check naming conventions" button (I wroteCodeTest Tool) write the following method

Private void btnnamecheck_click (Object sender, eventargs E)
{
This. pnlmain. Controls. Clear (); // initialize the main panel
Namerule Nr = new namerule (); // instantiate the form to be displayed in pnlmain (namerule is a new form)
Nr. toplevel = false; // set attributes
Nr. Show (); // display form
This. pnlmain. Controls. Add (NR); // Add from to pnlmain
}

In this way, click the naming convention check button to display the new form in the panel.

Similarly, write the same method in another button to open another form.

Private void btncodelinecheck_click (Object sender, eventargs E)
{
This. pnlmain. Controls. Clear ();
Codelinecount CLC = new codelinecount ();
CLC. toplevel = false;
CLC. Show ();
This. pnlmain. Controls. Add (CLC );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.