/// <summary>
/// 编 码 人:苏飞
/// 官方网址:http://www.sufeinet.com
/// </summary>
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);
}
}
}
}
/// <summary>
/// 编 码 人:苏飞
/// 官方网址:http://www.sufeinet.com
/// </summary>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Startup
{
public partial class frmstartup : Form
{
private bool _Exit;
public bool Exit
{
get { return _Exit; }
}
public frmstartup()
{
InitializeComponent();
}
private void frmstartup_Load(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Program.InitApp), this);
}
//显示文字信息
public void PrintMsg(Object msg)
{
lblMsg.Text = msg.ToString();
}
//关闭启动窗体,如果需要中止程序,传参数false
public void CloseForm(Object o)
{
this._Exit = Convert.ToBoolean(o);
this.Close();
}
}
}
你很聪明 发表于 2013-11-27 22:28
startup.Invoke(new UiThreadProc(startup.PrintMsg), "正在初始化...");
这种类型的语句,看不懂,,, ...






天上跑着玩 发表于 2017-9-6 09:57
验真身份的那个窗体是怎么把上面的关闭等按键去掉的,而且图片还是拉伸的?
站长苏飞 发表于 2017-9-6 11:20
这个自己看代码吧


| 欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |