C#Winform之等待窗体
窗体主要代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
public partial class frmWaitingNew : Form { public frmWaitingNew() { InitializeComponent(); } private delegate void SetTextHandler(string text); public void SetText(string text) { if (this.lbl_UserMsg.InvokeRequired) { this.Invoke(new SetTextHandler(SetText), text); } else { this.lbl_UserMsg.Text = text; } } public bool IsShown = false; DateTime StarTime; private void frmWaitingNew_Shown(object sender, EventArgs e) { StarTime = ConvertEx.ToDateTimeEx("2014-06-15"); timer1.Start(); IsShown = true; } int RunSeconds = 0; private void timer1_Tick(object sender, EventArgs e) { txt_Time.Text = StarTime.AddSeconds(++RunSeconds).ToString("mm:ss"); } } |
等待窗体调用类:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/// /// Using Singleton Design Pattern /// public class WaitFormService { public static void CreateWaitForm() { WaitFormService.Instance.CreateForm(); } public static void CloseWaitForm() { WaitFormService.Instance.CloseForm(); } public static void SetWaitFormCaption(string text) { WaitFormService.Instance.SetFormCaption(text); } private static WaitFormService _instance; private static readonly Object syncLock = new Object(); public static WaitFormService Instance { get { if (WaitFormService._instance == null) { lock (syncLock) { if (WaitFormService._instance == null) { WaitFormService._instance = new WaitFormService(); } } } return WaitFormService._instance; } } private WaitFormService() { } private Thread waitThread; private frmWaitingNew waitForm; public void CreateForm() { try { if (waitThread != null) { try { waitThread.Abort(); waitThread.Join(); } catch (Exception) { } } while (waitThread != null Thread.Sleep(200); waitThread = new Thread(new ThreadStart(delegate() { waitForm = new frmWaitingNew(); Application.Run(waitForm); })); waitThread.Start(); ThreadWaite(); } catch (Exception ex) { string sm = ex.Message; } } void ThreadWaite() { Thread.Sleep(200); if (!waitThread.IsAlive || waitForm == null || !waitForm.IsShown) Thread.Sleep(20); } public void CloseForm() { if (waitThread != null) { try { //waitThread.Abort(); //就是在分页里面,不停的按下一页,下一页。Application.Run(waitForm);就会报错。使用下面代码 //waitForm.Close(); //waitForm.Dispose(); ThreadWaite(); waitForm.Invoke(new DClose(Close), null); waitThread.Abort(); waitThread.Join(); waitThread.DisableComObjectEagerCleanup(); } catch (Exception ex) { Thread.Sleep(200); ThreadWaite(); waitForm.Invoke(new DClose(Close), null); waitThread.Abort(); waitThread.Join(); waitThread.DisableComObjectEagerCleanup(); } } } public delegate void DClose(); public void Close() { while ((int)waitForm.Handle Thread.Sleep(20); waitForm.Close(); } public void SetFormCaption(string text) { if (waitForm != null) { try { waitForm.SetText(text); } catch (Exception) { } } } } |
Demo下载地址:http://pan.baidu.com/s/1pJ9HSRD
C#Winform之等待窗体的更多相关文章
- (二十三)c#Winform自定义控件-等待窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- 【C#】分享带等待窗体的任务执行器一枚
-------------201504161039更新------------- 更新内容: IWaitForm接口删除System.Windows.Forms.DialogResult Dialog ...
- c# winForm 等待窗体的实现
最近在做一个项目,需要用到等待窗体,在DevExpress下面有SplashScreen控件可以使用,同时也有ProgressIndicator控件能用,但是如果没有用Dev开发的话,我们就需要自定义 ...
- 【C#】带等待窗体的BackgroundWorker
---------------201504170911更新--------------- 更新内容:删除bgwUI新增的Start方法,改为通过new修饰符+可选参数的方式同时覆盖基类(Backgro ...
- C#中的“等待窗体”对话框
这篇文章向您展示了如何在c#.net Windows窗体应用程序中创建一个等待窗体对话框.创建一个新表单,然后输入您的表单名称为frmWaitForm.接下来,将Label,Progress Bar控 ...
- winform打开子窗体后,在子窗体中刷新父窗体,或者关闭子窗体刷新父窗体
winform打开子窗体后,在子窗体中刷新父窗体,或者关闭子窗体刷新父窗体,搜集了几个方法,列举如下: 一 . 所有权法 父窗体,名称为“fuForm”,在父窗体中有个公共刷新方法,也就是窗体数据初始 ...
- Devexpress 等待窗体
加载窗体以及等待窗体 程序加载时,需要等待加载完成后在显示 窗体显示顺序 1. 给用户看的等待窗体 2. 加载完成后的主窗体 代码如下: 1. 等待窗体代码 #region using using S ...
- C#关于等待窗体(转)
c#.net 中如果想在主窗口A里点击打开新窗口B(因为要数据库操作,Bload需一小段时间)之前弹出带有滚动条等待子窗口C来提示用户没有死机,应该怎么做?我用多线程打开了c窗口,但是问题:1.C窗口 ...
- WinForm中一个窗体调用另一个窗体
[转] WinForm中一个窗体调用另一个窗体的控件和事件的方法(附带源码) //如果想打开一个 Form2 的窗体类,只需要: Form2 form = new Form2(); //有没有参数得看 ...
随机推荐
- Maven - error in opening zip file
在一个maven工程中,有时执行mvn打包,部署,编译等命令,例如mvn clean install -DskipTests -U等命令时,会报类似(error in opening zip file ...
- 安装Reshaper后Intellisense失效
安装Reshaper后Intellisense失效或希望用vs2017的Intellisense功能 安装完毕后,IDE 的智能提示(Intellisense)便会默认使用 Resharper 的提示 ...
- nginx 使用ngx_cache_purge清除缓存
location ~ ^/myclear(/.*) { allow 10.0.0.0/8; allow 10.28.100.0/24; allow 127.0.0.1; deny all; pro ...
- Eclipse个最实用的快捷键
一个Eclipse骨灰级开发人员总结了他觉得最实用但又不太为人所知的快捷键组合.通过这些组合能够更加easy的浏览源码,使得总体的开发效率和质量得到提升. 1. ctrl+shift+r:打开 ...
- Convert to a source folder or rename it.
从GitHub上恢复之前的版本 eclipse 报错: Convert to a source folder or rename it. 网上找了答案 : 找到了这个 1. 删除gen文件. 2.选 ...
- HDU 5294 Tricks Device (最大流+最短路)
题目链接:HDU 5294 Tricks Device 题意:n个点,m条边.而且一个人从1走到n仅仅会走1到n的最短路径.问至少破坏几条边使原图的最短路不存在.最多破坏几条边使原图的最短路劲仍存在 ...
- python 的三元表达式
python中的三目运算符不像其他语言 其他的一般都是 判定条件?为真时的结果:为假时的结果 如 result=5>3?1:0 这个输出1,但没有什么意义,仅仅是一个例子. 而在python中的 ...
- xcode下载低版本模拟器速度缓慢解决方案
随着苹果系统的更新和迭代,现在app开发中需要适配的除了需要适配屏幕尺寸以外,还需要适配系统版本.系统版本测试如果有条件可以使用各种系统版本的真机进行适配,如果没有这个条件,也可以采用xcode的模拟 ...
- linux下常用网页查看下载工具--wget
http://www.linuxidc.com/Linux/2015-06/118256.htm 5 个基于Linux命令行的文件下载和网站浏览工具 rTorrent.wget.cURL.w3m.El ...
- 查看Linux服务器的物理状态
1.当前内存使用情况 [user@host ~]$ free -m 2.当前CPU使用情况 [user@host ~]$ top 3.当前硬盘使用状态 [user@host ~]$ df -lh 4. ...