C# winform 启动画面支持多种 framework
- 博客分类:
- 技术杂绘
using System; using System.Collections.Generic; using System.Linq; using System.Text; //启动窗体虚基类,继承自ApplicationContext using System.Windows.Forms; using System.Threading; namespace TransmissionLine.PublicClass { public abstract class ShelterfromClass : ApplicationContext { private Form _SplashScreenForm;//启动窗体 private Form _PrimaryForm;//主窗体 private System.Timers.Timer _SplashScreenTimer; private int _SplashScreenTimerInterVal = 20000;//默认是启动窗体显示20秒 private bool _bSplashScreenClosed = false; private delegate void DisposeDelegate();//关闭委托,下面需要使用控件的Invoke方法,该方法需要这个委托 public ShelterfromClass() { this.ShowSplashScreen();//这里创建和显示启动窗体 this.MainFormLoad();//这里创建和显示启动主窗体 } protected abstract void OnCreateSplashScreenForm(); protected abstract void OnCreateMainForm(); protected abstract void SetSeconds(); protected Form SplashScreenForm { set { this._SplashScreenForm = value; } } protected Form PrimaryForm {//在派生类中重写OnCreateMainForm方法,在MainFormLoad方法中调用OnCreateMainForm方法 // ,在这里才会真正调用Form1(主窗体)的构造函数,即在启动窗体显示后再调用主窗体的构造函数 // ,以避免这种情况:主窗体构造所需时间较长,在屏幕上许久没有响应,看不到启动窗体 set { this._PrimaryForm = value; } } protected int SecondsShow {//未设置启动画面停留时间时,使用默认时间 set { if (value != 0) { this._SplashScreenTimerInterVal = 1000 * value; } } } private void ShowSplashScreen() { this.SetSeconds(); this.OnCreateSplashScreenForm(); this._SplashScreenTimer = new System.Timers.Timer(((double)(this._SplashScreenTi merInterVal))); _SplashScreenTimer.Elapsed += new System.Timers.ElapsedEventHandler(new System.Timers.ElapsedEventHandler(this.SplashScree nDisplayTimeUp)); this._SplashScreenTimer.AutoReset = false;//这句不处理控件带来的异常 Thread DisplaySpashScreenThread = new Thread(new ThreadStart(DisplaySplashScreen));//心跳开启 DisplaySpashScreenThread.Start(); } private void DisplaySplashScreen() { this._SplashScreenTimer.Enabled = true; Application.Run(this._SplashScreenForm); } private void SplashScreenDisplayTimeUp(object sender, System.Timers.ElapsedEventArgs e) { this._SplashScreenTimer.Dispose(); this._SplashScreenTimer = null; this._bSplashScreenClosed = true; } private void MainFormLoad() { this.OnCreateMainForm(); while (!(this._bSplashScreenClosed)) { Application.DoEvents(); } DisposeDelegate SplashScreenFormDisposeDelegate = new DisposeDelegate(this._SplashScreenForm.Dispose); this._SplashScreenForm.Invoke(SplashScreenFormDisp oseDelegate); this._SplashScreenForm = null; //必须先显示,再激活,否则主窗体不能在启动窗体消失后出现 this._PrimaryForm.Show(); this._PrimaryForm.Activate(); this._PrimaryForm.Closed += new EventHandler(_PrimaryForm_Closed); } private void _PrimaryForm_Closed(object sender, EventArgs e) { base.ExitThread(); } } } using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Runtime; using System.Runtime.InteropServices; namespace TransmissionLine { static class Program { /// /// 应用程序的主入口点。 /// //[STAThread] //static void Main() //{ // Application.EnableVisualStyles(); // Application.SetCompatibleTextRenderingDefault(fals e); // Application.Run(new Login()); //} //------------------------------------------------ ------------------------ //指示该属性化方法由非托管动态链接库 (DLL) 作为静态入口点公开。引入皮肤接口 [关键代码] [DllImport(@"appface.dll")] //注意路径 public static extern int SkinStart(string SkinFile, int nDefWinType, int CheckSum, int nType, int hInstance, int nLen); [DllImport(@"appface.dll")] public static extern int SkinRemove(); [DllImport(@"appface.dll")] public static extern int SkinWindowSet(IntPtr hWnd, int nSkintype); [DllImport(@"appface.dll")] public static extern int SkinWindowSetEx(IntPtr hWnd, int nSkintype, int nResourceId, int nUrfLoadType, string SkinFile, int hInstance, int nLen); //------------------------------------------------ ------------------------ [STAThread] static void Main() { //加载皮肤(加载你需要的皮肤,注意路径)[关键代码] SkinStart("skins\\basic_urf\\winmp_af.urf", 0, 0, 1, 0, 0); //第一次循环 LoginContext loginContext = new LoginContext(); Application.Run(loginContext); SkinRemove();//[关键代码] if (Login.LoginResult == true) //必须判断登陆是否成功,如果为真才执行下面操作,打开主页面 {//第二次循环 //加载皮肤(加载你需要的皮肤,注意路径)[关键代码] //SkinStart("skin\\plex.urf", 0, 0, 1, 0, 0); //SkinStart("skin\\leaf.urf", 0, 0, 1, 0, 0); //Second Message Loop try { Application.Run(new mycontext()); } catch { } //SkinRemove();//[关键代码] } //else if (dpMain.logout == true) //{ // MainContext mainContext = new MainContext(); // Application.Run(mainContext); //} } public class LoginContext : ApplicationContext { private Login loginDialog; public LoginContext() { loginDialog = new Login(); loginDialog.StartPosition = FormStartPosition.CenterScreen; loginDialog.Closed += new EventHandler(OnFormClosed); loginDialog.Show(); } private void OnFormClosed(object sender, EventArgs e) {//页面关闭时执行的操作 if (Login.LoginResult == true) {//为真打开主页面 Login.LoginResult = !(this.loginDialog.DialogResult == DialogResult.Cancel); ExitThread(); } else {//否则关闭线程 //Application.Exit(); ExitThread(); } } } //public class MainContext : ApplicationContext //{ // private dpMain mainForm; // public MainContext() // { // mainForm = new dpMain(); // mainForm.StartPosition = FormStartPosition.CenterScreen; // mainForm.Closed += new EventHandler(OnFormClosed); // mainForm.Show(); // //mainForm.Hide(); // } // private void OnFormClosed(object sender, EventArgs e) // {//页面关闭时记录操作 // ExitThread(); // } //} //启动窗体类(继承自启动窗体虚基类),启动画面会停留一段时间,该时间是设定的时间和主窗体构造所需时间两个的最大值 public class mycontext : PublicClass.ShelterfromClass { protected override void OnCreateSplashScreenForm() { this.SplashScreenForm = new Shelterfrom();//启动窗体 } protected override void OnCreateMainForm() { this.PrimaryForm = new dpMain();//主窗体 } protected override void SetSeconds() { this.SecondsShow = 2;//启动窗体显示的时间(秒) } } } }
发表评论
-
GDI中获取字符串精确绘制范围的两种做法比较
2012-07-06 09:52 654作者:朱金灿 ... -
使用正则表达式处理邮件模板中的参数
2012-07-06 09:45 654软件开发过程中,经常使用JavaMail给用户发送邮件;大 ... -
正则表达式 cscope emacs svn putty emacs
2012-07-06 09:38 770我一懒人,图自己方便。要是路过的朋友们用上了的话,请给懒人 ... -
18位身份证验证代码
2012-07-05 20:45 799首先php版本的: /** * 身份证 * * @para ... -
在Flex组件上显示手型的鼠标
2012-07-03 13:44 668在Flex组件上显示手型的鼠标 有些时候,我们需要 ... -
Flex学习笔记
2012-07-02 12:46 560类成员有四种修饰 ... -
关于Firefox重新加载flex的问题解决
2012-07-02 12:46 832DIV中有一个flex,我希望用js来控制它的显示和隐藏, ... -
flex取数据1
2012-07-02 12:45 532HTML通过JavaScript传递信息到Flex中 ... -
Pivot升级为Apache顶级项目,准备好挑战Flex, Silverlight和JavaFX
2012-07-02 12:45 612Apache软件基金会(ASF)于昨天宣布,将Pivot ... -
Flex控制对主机网页中脚本的访问
2012-07-02 12:45 513通过使用以下 ActionScript 3.0 API 可 ... -
视频聊天网站的研究、发展以及趋势(转)
2012-07-01 10:07 518此文讲述了视频聊 ... -
Ubuntu 10.04环境下载&编译Android-2.2.1 (froyo )
2012-07-01 10:07 1016本文根据下文整理而成: http://mantocom.b ... -
转载:WebKit介绍及总结(三)
2012-07-01 10:07 674六 . 编译与调试 在 ubuntu-10.04 上 ... -
ExtJS 4 Grid组件
2012-07-01 10:07 610我们正 ... -
[转载]flex开源框架汇总-leo_wlcnblogs-博客园
2012-06-30 16:34 689[转载]flex开源框架汇总-leo_wlcnblogs-博客 ... -
【FLEX学习】第五天
2012-06-30 16:34 572【FLEX学习】第五天 2011年02月17日 1.细化 ... -
使用Flex和Actionscript开发Flash游戏―(八)
2012-06-30 16:34 499使用Flex和Actionscript开发Flash游戏―(八 ... -
使用Flex3.0 AIR 创建“不规则形状”的Air透明窗体
2012-06-30 16:34 560使用Flex3.0 AIR 创建“不规则形状”的Air透明窗体 ... -
ria big bang = {flash/air/flex .vs. html5}_chriswang
2012-06-30 16:34 605ria big bang = {flash/air/flex ...
相关推荐
C# 一个简单例子 WinForm程序添加启动画面 Visual Studio 2015和Visual Studio 2017 运行ok,电脑里只有这两个版本。 非常简单的例子,新人学习用!
C# winform 上传文件 (多种方案)
c# winform 窗体样式风格 多种漂亮好看的样式风格 下拉框选择
c# winform 绘制多行文本:自动换行:文本c# winform 绘制多行文本:自动换行:文本c# winform 绘制多行文本:自动换行:文本c# winform 绘制多行文本:自动换行:文本c# winform 绘制多行文本:自动换行:文本c# winform 绘制...
C# WinForm程序添加启动画面的方法
C# Winform 通用导航菜单C# Winform 通用导航菜单C# Winform 通用导航菜单C# Winform 通用导航菜单C# Winform 通用导航菜单C# Winform 通用导航菜单
串口扫码枪 收发数据样例并实现串口监控 c# winform串口扫码枪 收发数据样例并实现串口监控 c# winform串口扫码枪 收发数据样例并实现串口监控 c# winform串口扫码枪 收发数据样例并实现串口监控 c# winform串口扫码...
C# winform 万能打印模板,可以打印证书,修改证书参数,C#窗体程序,代码注释详细 C# winform 万能打印模板,可以打印证书,修改证书参数,C#窗体程序,代码注释详细 C# winform 万能打印模板,可以打印证书,修改...
Microsoft Visual Studio 2010做的C# winform类的静态成员及静态方法,主要代码: public class Student { private int IDBase = 20080000; private int ID; public static int StudentNumber; public string ...
C#winform调用电脑摄像头
C#编程 WinForm窗体开发 ChineseCode(源码)C#编程 WinForm窗体开发 ChineseCode(源码)C#编程 WinForm窗体开发 ChineseCode(源码)C#编程 WinForm窗体开发 ChineseCode(源码)C#编程 WinForm窗体开发 ChineseCode(源码)...
C# winform 获取 本机 IP C# winform 获取 本机 IP
一款还不错的C#winform开发框架,对于想学习C#框架的初学者来说,是很值得借鉴的
C#绘图winform程序(免积分下载),支持多种图元:线段、构造线、射线、多段线、圆、圆弧、文字。与复制移动伸缩等等功能,可以保存绘制的图形, 缩放和平移视图。 支持图层。 图元支持夹点,并且可以通过移动夹...
C# WinForm 读写XML文件 C# WinForm 读写XML文件
c# winform实例大全(198个Csharp WinForm实例源码)
C# WinForm 实践开发教程,很详细的一本书,想学习C# WinForm开发的必备书籍
经典C#WinForm小实例,真实代码。日常实用性较强,有需要欢迎关顾小店。
C#winform调用webapi 上传json格式字符串,返回json字符串结果
198个经典C#winform源码,精美界面,每个界面都有源码。