【小白专用】winform启动界面+登录窗口 更新2024.1.1

需求场景:先展示启动界面,然后打开登录界面,如果登录成功就跳转到主界面

首先在程序的入口路径加载启动界面,使用ShowDialog显示界面,

然后在启动界面中添加定时器,来实现显示一段时间的效果,等到时间到了就关闭

启动界面的窗口。传递一个对象给登录界面,用来保存登录状态,显示登录界面,

如果登录成功就在登录界面中对这个传递进来的对象就行修改,这里使用1作为成功

的返回值,注意这里也需要使用ShowDialog来打开这个窗口。等到登录窗口关闭后

判断这个返回值,如果为成功则显示用户主界面,如果不成功的话程序就会直接退出。

主要代码如下

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;

        }



    }
}

猜你喜欢

转载自blog.csdn.net/zgscwxd/article/details/135325172