Classic examples of loading interfaces in C #

Source: Internet
Author: User
This article mainly introduces C # loading interface of common methods, involving the operation of the form, very practical value, the need for friends can refer to the following

The examples in this article describe common methods for loading interfaces in C #. Share to everyone for your reference. The specific methods are analyzed as follows:

Method 1: Use the event delegate method
Objects: Main form: frmmain load form: frmloading
Ideas:
Show Form frmloading before the main form loads, when the main form is finished loading (the first time it is displayed), close frmloading

The C # code looks like this:

The code is as follows:

using system;using system.collections.generic;using System.ComponentModel; Using system.data;using system.drawing;using system.linq;using system.text;using system.windows.forms;using        System.threading;namespace cdemotest{public partial class Frmmain:form {private frmloading loadform;            Public Frmmain () {//create load form loadform = new frmloading (); Specifies the event this is completed when the form is loaded.             shown + = Frmloading_close;            Loadform.show ();            Main form initialization Method InitializeComponent ();        }//Declaration closed load form method private void Frmloading_close (object sender, EventArgs e) {loadform.close ();       } private void Frmmain_load (object sender, EventArgs e) {thread.sleep (3000); }   }}

Method 2.
① in the main method, display the splash screen first, and note that show is used instead of ShowDialog.
② then Application.Run (mainform) in the normal way;
③ starts the load thread in the MainForm constructor. A flag is set in the
④mainform, which is set to a value if the load is complete.
⑤ the form used as the splash screen, note that the flag is detected in MainForm, and if the main form is loaded, it shuts itself down.

Related Article

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.