代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
WinForm 等待窗口
作者:
Ansel
/ 发布于
2015/7/23
/
1047
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace BMSAP.Windows { class FrmWait : Form { ///<summary> /// Required designer variable. ///</summary> private System.ComponentModel.IContainer components = null; ///<summary> /// Clean up any resources being used. ///</summary> ///<param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code ///<summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///</summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.Dock = System.Windows.Forms.DockStyle.Fill; this.label1.Font = new System.Drawing.Font("Microsoft YaHei", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.Location = new System.Drawing.Point(0, 0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(386, 60); this.label1.TabIndex = 0; this.label1.Text = "正 在 处 理 请 稍 候 "; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // FrmWait // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(386, 60); this.ControlBox = false; this.Controls.Add(this.label1); this.Font = new System.Drawing.Font("Microsoft YaHei", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "FrmWait"; this.ShowIcon = false; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Label label1; public FrmWait() { InitializeComponent(); } } public delegate void ExecutedInvokeHeandle(); ///<summary> /// 等待窗口 ///</summary> public class WaitForm { ///<summary> /// 等待窗口对象 ///</summary> static FrmWait mWait; ///<summary> /// 事件状态通知 ///</summary> static AutoResetEvent mEvents; ///<summary> /// 显示状态 ///</summary> static bool mShowing = false; ///<summary> /// 等待状态 ///</summary> static bool mWaiting = false; static WaitForm() { //全局等待信号 mEvents = new AutoResetEvent(false); } ///<summary> /// 窗口关闭事件 ///</summary> ///<param name="sender"></param> ///<param name="e"></param> static void WaitForm_FormClosed(object sender, FormClosedEventArgs e) { if (mWaiting || !(sender is FrmWait)) { //信号等待中被异常关闭,或主窗口被关闭时自动通知信号复位 mEvents.Set(); return; } mShowing = false; //回收等待窗口 try { mWait.Dispose(); } finally { mWait = null; } } ///<summary> /// 显示等待窗口 ///</summary> ///<param name="pComponet">调用对象,可为控件或窗口</param> public static void Show(Control pComponet) { //已显示则返回 if (mShowing) return; //创建等待窗口 mWait = new FrmWait(); //设置窗口关闭事件 mWait.FormClosed += new FormClosedEventHandler(WaitForm_FormClosed); //启动显示线程 Thread tmpThread = new Thread(show); tmpThread.Start(pComponet); } ///<summary> /// 关闭等待窗口 ///</summary> public static void Close() { if (mShowing) //如果显示中则设置关闭信号 mEvents.Set(); //修改等待状态 mWaiting = false; } ///<summary> /// 显示窗口过程 ///</summary> ///<param name="pComponet"></param> static void show(object pComponet) { if (pComponet != null && pComponet is Control) { //设置显示状态 mShowing = true; //当调用对象为Win控件时 (pComponet as Control).BeginInvoke(new ExecutedInvokeHeandle(delegate() { //进行异步调用 if (pComponet != null && pComponet is Control) { //显示等待窗口 mWait.Show((pComponet as Control).FindForm()); //设置父级窗口关闭事件 (pComponet as Control).FindForm().FormClosed += new FormClosedEventHandler(WaitForm_FormClosed); //激活父级窗口, (pComponet as Control).FindForm().Activate(); } else { //如查询不到父级窗口设置顶层显示,此处可用GetDesktop的API来获取桌面窗口,并设置为父级窗口 mWait.TopMost = true; //显示等待窗口 mWait.Show(); } })); //设置等待信号 mWaiting = true; mEvents.WaitOne(); //等待结束 mWaiting = false; (pComponet as Control).BeginInvoke(new ExecutedInvokeHeandle(delegate() { //关闭窗口 mWait.Close(); })); } } } }
试试其它关键字
WinForm
等待窗口
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Ansel
贡献的其它代码
(
2
)
.
获取 SQL服务器列表
.
WinForm 等待窗口
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3