方法一、program.cs 中先启动欢迎窗体,然后注册程序运行空闲去执行主程序窗体相应初始化代码

  static void Main(string[] args)
{
Application.EnableVisualStyles(); //样式设置
Application.SetCompatibleTextRenderingDefault(false); //样式设置 UIForm.WelcomeForm sp = new UIForm.WelcomeForm(); //启动窗体
sp.Show(); //显示启动窗体
context = new ApplicationContext();
context.Tag = sp;
Application.Idle += new EventHandler(Application_Idle); //注册程序运行空闲去执行主程序窗体相应初始化代码
Application.Run(context);
}
     //初始化等待处理函数
private static void Application_Idle(object sender, EventArgs e)
{ Application.Idle -= new EventHandler(Application_Idle);
if (context.MainForm == null)
{
MainForm mw = new MainForm(_args);
context.MainForm = mw;
mw.InitForm(); //主窗体要做的初始化事情在这里,该方法在主窗体里应该申明为public
UIForm.WelcomeForm sp = (UIForm.WelcomeForm)context.Tag;
sp.Close(); //关闭启动窗体
mw.Show(); //启动主程序窗体
} }

方法二、实现一个Splasher类,由主窗体操作欢迎窗体(受益于大神:键盘敲击者cncxz http://www.cnblogs.com/cncxz/archive/2006/07/14/450987.html)

首先创建一个名为ISplashForm的接口,该接口包含一个名为SetStatusInfo的方法以用来在启动屏幕上设置系统加载状态,代码如下:

  public interface ISplashForm
{
void SetStatusInfo(string statusInfo);
}

然后实现一个Splasher类,负责欢迎窗体的Show、Close和Status更新,代码如下:

   public class Splasher
{
private static Form splashForm = null;
private static ISplashForm splashInterface = null;
private static System.Threading.Thread splashThread = null;
private static string tempStatus = string.Empty; public static void Show(Type splashFormType)
{
if (splashThread != null)
{
return;
}
if (splashFormType == null)
{
throw new Exception("必须设置启动窗体");
}
splashThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
{
createInstance(splashFormType);
Application.Run(splashForm);
}));
splashThread.IsBackground = true;
splashThread.SetApartmentState(System.Threading.ApartmentState.STA);
splashThread.Start();
}
public static void Close()
{
if (splashThread == null || splashForm == null) return;
try
{
splashForm.Invoke(new MethodInvoker(splashForm.Close));
}
catch (Exception ex)
{
Controller.MessageConsole.WriteLog(ex);
HttpProxy.LogProxy.DoTask(ex, Controller.SQLiteController.Biz.GetAuthor());
}
splashThread = null;
splashForm = null;
}
public static string Status
{
set
{
{
if (splashInterface == null || splashForm == null)
{
tempStatus = value;
return;
}
splashForm.Invoke(
new splashStatusChangedHandle(delegate(string str) { splashInterface.SetStatusInfo(str); }),
new object[] { value }
);
}
}
}
private static void createInstance(Type FormType)
{
object obj = FormType.InvokeMember(null, System.Reflection.BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
splashForm = obj as Form;
splashInterface = obj as ISplashForm;
if (splashForm == null)
{
throw new Exception("启动窗体类型必须是System.Windows.Forms.Form的子类");
}
if (splashInterface == null)
{
throw new Exception("启动窗体必须实现ISplashForm接口");
}
if (!string.IsNullOrEmpty(tempStatus))
{
splashInterface.SetStatusInfo(tempStatus);
}
}
private delegate void splashStatusChangedHandle(string NewStatusInfo);
}

欢迎窗体代码如下:

  public partial class WelcomeForm : DevExpress.XtraEditors.XtraForm, ISplashForm
{
public WelcomeForm()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;//取消窗体边框
this.ShowInTaskbar = false;//取消任务栏图标显示
} public void SetStatusInfo(string statusInfo)
{
this.lbInfo.Text = statusInfo;
}
}

主窗体需要初始化的地方调用代码如下:

           Splasher.Status = "正在初始化窗体...";
InitializeComponent();
//一系列初始化操作。。。
//为Splasher.Status复制实现消息通知
Splasher.Close();

program.cs Main函数中实现代码如下:

    UI.UIForm.Splasher.Show(typeof(UIForm.WelcomeForm));
Application.Run(new MainForm(args));

C# Winform欢迎窗体实现()的更多相关文章

  1. Winform子窗体刷新父窗体

    调用窗体(父):Form1,被调用窗体(子):Form2方法1:   所有权法//Form1://需要有一个公共的刷新方法public   void   Refresh_Method(){//...} ...

  2. Winform跨窗体操作控件(使用委托)

    Winform跨窗体操作控件是winform开发中很常见的形式,最常见且简单有效的方式便是使用委托的方式来进行操作,下面我将通过一个小实例来说明如何使用委托跨窗体实现控件操作. 实例介绍:两个窗体,F ...

  3. WinForm 设置窗体启动位置在活动屏幕右下角

    WinForm 设置窗体启动位置在活动屏幕右下角 在多屏幕环境下, 默认使用鼠标所在的屏幕 1. 设置窗体的 StartPosition 为 FormStartPosition.Manual. 2. ...

  4. WinForm之窗体应用程序

    WinForm之窗体应用程序 基本简单数据库操作(增删改查) using System; using System.Collections.Generic; using System.Windows. ...

  5. WinForm开发,窗体显示和窗体传值相关知识总结

    主窗体中代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void b ...

  6. C# winform中 窗体缩放自适应的方法(不同电脑/不同分辨率)

    C# winform中 窗体缩放自适应的方法(不同电脑/不同分辨率)   窗体缩放是一个困扰我多时的问题,为了解决这个问题,我从网上找了很多相关的资料,很多人说用Anchor和Dock属性,但是我试了 ...

  7. winform圆角窗体实现

    winform圆角窗体实现 1.窗体的FormBorderStyle设置成None,不要控制边框 2.TransparencyKey和BackColor颜色设置成相同的,这样,窗体就透明了 3.以此为 ...

  8. C# WinForm 父窗体 子窗体 传值

    C# WinForm 父窗体 子窗体 传值 本次示例效果如下:Form1为父窗体(包含textBox1.button1)Form2为子窗体(包含textBox2.button2) 父窗体给子窗体传值= ...

  9. c#winform自定义窗体,重绘标题栏,自定义控件学习

    c#winform自定义窗体,重绘标题栏 虽然现在都在说winform窗体太丑了,但是我也能尽量让桌面应用程序漂亮那么一点点话不多说,先上图 重绘标题栏先将原生窗体设置成无边框,FormBoderSt ...

  10. winform基础窗体设置及基础控件

    WinForm - 也叫做C/S  客户端 另:B/S是 网页端 客户端应用程序 - 是需要安装在用户电脑上才可以使用的程序 特点: 不需要联网也可以打开使用部分功能,但是现在的情况是许多功能依然需要 ...

随机推荐

  1. 终于解决了一个Win7 下 VS 编译的问题,困扰了我好几个月

    用 Win7 一年多了,一直在这个环境下编程,其他都挺好,就是有个问题非常恶心,在VS下编译经常出现进程正在使用,无法覆盖的错误,这个问题我记得博问中以前也有其他人遇到过,也没有解决掉.此问题困扰了我 ...

  2. bzoj 3625(CF 438E)The Child and Binary Tree——多项式开方

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3625 http://codeforces.com/contest/438/problem/E ...

  3. Linux测试程序 - 多线程

    #include <sched.h> #include <pthread.h> main(){ pthread_t id0, id1, id2; ret=pthread_cre ...

  4. 修改crushmap实验

    标签(空格分隔): ceph,ceph实验,crushmap CRUSH的全称是Controlled Replication Under Scalable Hashing,是ceph数据存储的分布式选 ...

  5. asp.netcore di 实现批量接口注入

    废话少说,先上代码 public static Dictionary<Type, Type[]> GetImpleAndInterfaces(string assemblyName,str ...

  6. Solaris10如何确认DirectIO是否已经启用

    对于Oracle而言,如果数据库存储在UFS文件系统上,启用DirectIO能够提高数据库性能.Oracle有个参数filesystemio_options可以控制数据库是否使用DirectIO.  ...

  7. javascript——常用函数

    1.获取随机数: function GetRandomNum(n, m) { //n-m之间的随机数 return Math.floor(Math.random() * (m - n + 1) + n ...

  8. C# 正规表达式

    在C#中怎么用正则表达式限制文本框内不能输入数字?只能输入数字:"^[0-9]*$".只能输入n位的数字:"^\d{n}$".只能输入至少n位的数字:" ...

  9. AFNetworking-2.5-源码阅读剖析--网络请求篇

    一.前言 AFNetworking,非常友好简单的网络请求第三方框架,在GitHub中已经获得了25000++的star,链接地址:https://github.com/AFNetworking/AF ...

  10. MSSQL 当前数据库中已存在用户或角色,SQLServer2008,错误15023,

    原因: sql server中“登录”与“用户”的区别,“登录”用于用户身份验证,而数据库“用户”帐户用于数据库访问和权限验证.登录通过安全识别符 (SID) 与用户关联.将数据库恢复到其他服务器时, ...