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.