c# Winform 加载窗体
先来一个加载窗体代码
public partial class FrmLoading : Form
{
public BackgroundWorker updateDBWorker=new BackgroundWorker(); public Action BackgroundWorkAction
{
get;
set;
} public KeyValuePair<int, string> CurrentMsg
{
set
{
this.updateDBWorker.ReportProgress(value.Key, value.Value);
}
} public FrmLoading()
{
InitializeComponent();
this.updateDBWorker.WorkerReportsProgress = true;
this.updateDBWorker.WorkerSupportsCancellation = true;
this.updateDBWorker.DoWork += new DoWorkEventHandler(this.backgroundWorker1_DoWork);
this.updateDBWorker.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
this.updateDBWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
lblVer.Text = Properties.Resources.SystemVer;
} public void ShowLog(string strLog, int intValue)
{
if (this.lblLog.InvokeRequired)
{
this.lblLog.BeginInvoke(new MethodInvoker(delegate() { ShowLog(strLog, intValue); }));
}
else
{
lblLog.Text = strLog;
this.progressBar1.Value = intValue;
}
} private void FrmLoading_Load(object sender, EventArgs e)
{
this.updateDBWorker.RunWorkerAsync();
} private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
if (this.BackgroundWorkAction != null)
{
this.BackgroundWorkAction();
}
Thread.Sleep();
if (base.InvokeRequired)
{
base.BeginInvoke(new MethodInvoker(delegate
{
base.Close();
}));
}
else
{
base.Close();
}
} private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
ShowLog((e.UserState == null) ? "" : e.UserState.ToString(), e.ProgressPercentage);
} private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
}
界面就一个进度条,一个label,没其他东西
看调用的地方,Program文件里面
FrmLoading frmLoading = new FrmLoading();
frmLoading.BackgroundWorkAction = delegate
{
try
{
//设置连接字符串
frmLoading.CurrentMsg = new KeyValuePair<int, string>(, "正在初始化数据配置..."); frmLoading.CurrentMsg = new KeyValuePair<int, string>(, "正在初始化日志配置...");
System.Threading.Thread.Sleep(); frmLoading.CurrentMsg = new KeyValuePair<int, string>(, "正在升级本地数据..."); frmLoading.CurrentMsg = new KeyValuePair<int, string>(, "正在初始化本地参数..."); frmLoading.CurrentMsg = new KeyValuePair<int, string>(, "正在初始化热键信息..."); frmLoading.CurrentMsg = new KeyValuePair<int, string>(, "正在初始化硬件设备..."); frmLoading.CurrentMsg = new KeyValuePair<int, string>(, "初始化完成..."); }
catch (Exception ex)
{
Application.Exit();
Process.GetCurrentProcess().Kill();
}
};
frmLoading.ShowDialog(); Application.Run(new form1());
好了 就这样了,没什么技术含量,就不贴图了,拿去用吧
c# Winform 加载窗体的更多相关文章
- C# Winform 加载窗体/对象时的等待页面设计
在设计应用程序过程中,有时候加载对象需时较长,我们可以显示一个Loading等待页面,对用户来说就比较友好了. 这个还是涉及到多线程,下面是步骤. 一.创建好Loading窗体: 一个Panel用于显 ...
- WinForm 加载自定义控件闪烁问题
WinForm加载多个自定义控件时,会出现很严重的闪烁问题,很卡,一块一块的加载(像打开网页时,网络很卡的那种感觉)简直没法忍受. 在网上搜索了好久,网上大部分的方法是一下4种,但是都不能有效的解决问 ...
- [转] 从 dll 程序集中动态加载窗体
无涯 原文 从 dll 程序集中动态加载窗体 [原创] 昨天晚上花了一晚上时间写了一个从程序集中动态加载窗体的程序.将任何包含窗体的代码编译成 dll 文件,再把 dll 文件拷贝到本程序的目录下,本 ...
- C# 多线程 异步加载 窗体
C# 多线程 异步加载 窗体 分类: C#2014-05-28 16:57 1286人阅读 评论(0) 收藏 举报 异步加载 我们在使用 windowform 编程的时候,我们或许可能会越到,各种在窗 ...
- 【转】C# winform 加载网页 模拟键盘输入自动接入访问网络
[转]C# winform 加载网页 模拟键盘输入自动接入访问网络 声明: 本文原创,首发于博客园 http://www.cnblogs.com/EasyInvoice/p/6070563.html ...
- (七十三)c#Winform自定义控件-资源加载窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- WinForm加载外部类库项目的集成开发模式
在项目开发中有一定的团队用到了Nuget.Coding:但是这用起来还是不太方方便,在Winform中呢,我们可以把一个人的项目当作一个类库项目,因为它生成的是一个dll文件,也就是单一文件,拥有了它 ...
- 通过特殊处理 Resize 事件解决 WinForm 加载时闪烁问题的一个方法
WinForm 上放置的控件多了或者有大背景图,窗体加载时就会闪烁,对于一般的闪烁,设置 DoubleBuffer=True或许有一点改善,要立竿见影的解决可以重载 CreateParams 使用 W ...
- c# WinForm加载焦点
1.c# WinForm在加载时把焦点设在按钮上 this.AcceptButton = button1; 这样在WinForm窗口中, 按钮的状态会变成窗口的默认按钮, 只要按下Enter键,就会触 ...
随机推荐
- 多次调用settimeout 如何使用单例模式
<script> function aaa() { window.counter = window.counter||1; console.log(window.counter); win ...
- linux命令--网络命令
一.网络命令 1.配置ip 1.1 配置 IP 地址 IP 地址是计算机在互联网中唯一的地址编码.每台计算机如果需要接入网络和其他计算机进行数 据通信,就必须配置唯一的公网 IP 地址. 配置 IP ...
- 如何获取JVM堆转储文件
堆转储是诊断与内存相关的问题(例如内存泄漏缓慢,垃圾回收问题和 java.lang.OutOfMemoryError.它们也是优化内存消耗的重要工具. 有很多很不错的的工具,例如Eclipse MAT ...
- 关于scrapy中如何区分是接着发起请求还是开始保存文件
一.区分 根据yield迭代器生成的对象是request对象还是item对象 二.item 1.配置tem对象 在items.py文件中设置类 class MyscrapyItem(scrapy.It ...
- flush() 缓冲输出流的缓冲区问题
package seday06; import java.io.BufferedOutputStream;import java.io.FileOutputStream;import java.io. ...
- Add an Item to the Navigation Control 将项目添加到导航控件
In this lesson, you will learn how to add an item to the navigation control. For this purpose, the N ...
- C#中 EF 性能优化
https://www.cnblogs.com/chenwolong/p/7531955.html EF使用AsNoTracking(),无跟踪查询技术(查询出来的数据不可以修改,如果你做了修改,你会 ...
- 031.[转] 从类状态看Java多线程安全并发
从类状态看Java多线程安全并发 pphh发布于2018年9月16日 对于Java开发人员来说,i++的并发不安全是人所共知,但是它真的有那么不安全么? 在开发Java代码时,如何能够避免多线程并发出 ...
- crossover mac如何使用?crossover mac使用教程
CrossOver Mac 破解版可以在 Mac 上运行成千上万的 Windows 程序,从办公软件.实用工具.游戏到设计软件.CrossOver 19 破解版可以让 Windows 程序和 Mac ...
- 201871010132-张潇潇《面向对象程序设计(java)》第一周学习总结
面向对象程序设计(Java) 博文正文开头 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cn ...