Home > Backend Development > C#.Net Tutorial > Classic example of loading interface in C#

Classic example of loading interface in C#

Y2J
Release: 2017-04-21 14:15:01
Original
3011 people have browsed it

This article mainly introduces the common methods of loading interface in C#, involving the operation of forms, which is of great practical value. Friends in need can refer to it

The example of this article describes the loading interface in C# common methods. Share it with everyone for your reference. The specific method analysis is as follows:

Method 1. Using event delegation method
Object: Main form: FrmMain Loading form: FrmLoading
Idea:
Display the window before the main form is loaded Body FrmLoading, when the main form is loaded (when it is displayed for the first time), close FrmLoading

The C# code is as follows:

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()
        {
            //创建加载窗体
             loadForm = new FrmLoading();
            //指定窗体加载完毕时的事件
            this.Shown += FrmLoading_Close; 
            loadForm.Show();
            //主窗体初始化方法
            InitializeComponent();
            }
        //声明关闭加载窗体方法
        private void FrmLoading_Close(object sender, EventArgs e)
        {
        loadForm.Close();
        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
        Thread.Sleep(3000);
       }
   }
}
Copy after login

Method 2 .
① In the Main method, display the startup screen first, and be careful to use Show instead of ShowDialog.
② Then follow the normal way, Application.Run(mainForm);
③ In the constructor of mainForm, start the loading thread.
④ Set a flag in mainForm. If the loading is completed, the flag is set to a certain value.
⑤ For the form used as the startup screen, pay attention to detecting the flag in mainForm. If the main form is loaded, it will close itself.

The above is the detailed content of Classic example of loading interface in C#. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
c#
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template