Close the first Form window in C # and open another new window method

Source: Internet
Author: User
Tags log log

1 Hidden method, the principle is to hide the old window, and then open a new window.

Create a new NewForm window (NewForm is your own defined form) NewForm fm=new NewForm ()

This. Hide ();//hidden now this window FM. Show ();//New window appears

This way the old window will still account for the memory, so if used to do landing window is not very good, but if the old window is still need to restore the main window, this method is very good, because you can close the new window, and then use the old window. Show () Can restore the old window. So this method is suitable for passing information between the main window and the child window.

2, come again is the method for the login window design. In Program.cs this defines:

static void Main () {application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (FALSE);

New Login window (login is your own definition of form) login Log = new Login ();

Use the modal dialog box method to display the Log log.showdialog ();

DialogResult is used to determine whether to return the parent form's if (Log.dialogresult = = DialogResult.OK) {//Open main form Application.Run in thread (new Main ());}} After verification is completed in the login window, assign the value Log.dialogresult = DialogResult.OK. The login window will be turned off after completing the task, and the main window will open.

Close the first Form window in C # and open another new window method

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.