[Exclusively for newbies] Winform startup interface + login window updated 2024.1.1

Demand scenario: First display the startup interface, then open the login interface, and jump to the main interface if the login is successful.

First, load the startup interface in the entry path of the program, and use ShowDialog to display the interface.

Then add a timer to the startup interface to achieve the effect of displaying it for a period of time, and then close it when the time is up.

The window that launches the interface. Pass an object to the login interface to save the login status and display the login interface.

If the login is successful, the passed object can be modified in the login interface. Here, 1 is used as success.

The return value. Note that ShowDialog is also needed to open this window. Wait until the login window closes

Judge this return value. If it is successful, the user main interface will be displayed. If it is unsuccessful, the program will exit directly.

The main code is as follows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AliWorkbenchProgram
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);




            //启动界面
            loadFrm form = new loadFrm();
            form.ShowDialog();
            //保存返回值
            int[] loginResult = new int[] { 0 };
            //传递返回值对象给登录窗口
            loginFrm main = new loginFrm(loginResult);
            main.ShowDialog();
            //由于使用的是ShowDialog,所有只有在窗口关闭后才会继续向下执行
            if (loginResult[0] == 1)
            {
                //打开主界面
                Application.Run(new mainFrm());
            }





        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AliWorkbenchProgram
{
    public partial class loginFrm : Form
    {
        public loginFrm(int[] loginResult)
        {
            InitializeComponent();

            loginResult[0] = 1;

        }



    }
}

Guess you like

Origin blog.csdn.net/zgscwxd/article/details/135325172