基本信息
源码名称:winform 软件初始化效果与多界面启动 C#实例源码
源码大小:0.19M
文件格式:.zip
开发语言:C#
更新时间:2017-11-13
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

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

namespace Startup
{
	static class Program
	{
		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			MyApplicationContent appContent = new MyApplicationContent(new frmMain(), new frmstartup());
			Application.Run(appContent);
		}

		//模拟耗时操作,这里假调程序需要访问网络来实现登录验证
		//这是一个耗时操作,我们需要在执行的过程中,向用户实时显示一些信息
		//那么,多线程是唯一的解决方案,在主线程执行这些,界面会死掉的
		public static void InitApp(Object parm)
		{
			frmstartup startup = parm as frmstartup;
			startup.Invoke(new UiThreadProc(startup.PrintMsg), "正在初始化...");
			Thread.Sleep(100);
			startup.Invoke(new UiThreadProc(startup.PrintMsg), "正在验证用户身份信息...");
			Thread.Sleep(2000);
			startup.Invoke(new UiThreadProc(startup.PrintMsg), "用户身份验证成功。");
			Thread.Sleep(500);
			startup.Invoke(new UiThreadProc(startup.PrintMsg), "正在登录...");
			Thread.Sleep(2000);
			startup.Invoke(new UiThreadProc(startup.PrintMsg), "登录成功,欢迎使用!");
			//这里可以根据执行的结果判断,如果登录失败就退出程序,否则显示主窗体
			if (true)
			{
				startup.Invoke(new UiThreadProc(startup.CloseForm), false);
			}
			else
			{
				startup.Invoke(new UiThreadProc(startup.CloseForm), true);
			}
		}
	}

	public delegate void UiThreadProc(Object o);
	//WinForm里,默认第一个创建的窗体是主窗体,所以需要用应用程序域来管理
	public class MyApplicationContent : ApplicationContext
	{
		private Form realMainForm;

		public MyApplicationContent(Form mainForm, Form flashForm)
			: base(mainForm)
		{
			this.realMainForm = mainForm;
			this.MainForm = flashForm;
		}

		protected override void OnMainFormClosed(object sender, EventArgs e)
		{
			if (sender is frmstartup)
			{
				frmstartup frm = sender as frmstartup;
				
                if (!frm.Exit)
				{
					this.MainForm = realMainForm;

					realMainForm.Show();
				}
				else
				{
					base.OnMainFormClosed(sender, e);
				}
			}
			else
			{
				base.OnMainFormClosed(sender, e);
			}
		}
	}
}