- 浏览: 682036 次
- 性别:
- 来自: 沈阳
文章分类
- 全部博客 (270)
- Ant Tool Script (12)
- XMLDigest (5)
- MyEclipse8.6 (1)
- RedHat (5)
- SVNVersionController (4)
- BatOperation (6)
- JspAndFaceWeb (66)
- javaSwing (18)
- PHP (12)
- J2SE (6)
- TestToolAndTestManual (12)
- C# (34)
- Java PatternDesign (20)
- Axis2AndWebService (5)
- ITLive (2)
- DBAndControl (10)
- C/C++ (8)
- Andriod (7)
- Python (7)
- JavaWork (16)
- Android-QA (1)
- Apache-Wicket (1)
- POI (1)
- JQuery (2)
- Struts2 (1)
- Flex&Flash (6)
- sdsdsd (0)
- 1212 (0)
最新评论
-
anayomin:
对九楼继续改进
public static <T> ...
Java List 分页 -
H4X0R:
来学习学习,赞一个
Aqua Data Studio 导出SQL -
yankai0219:
现在出现这个错误 Fatal error: Class 'PH ...
纯PHP搭建Apache+Eclipse+xDebug+PHPUnit+MakeGood -
yankai0219:
您好,我在搭建环境中提示PHPUnit_Framework_T ...
纯PHP搭建Apache+Eclipse+xDebug+PHPUnit+MakeGood -
wilsonchen:
chenhailong 写道wilsonchen 写道chen ...
C# RSA和Java RSA互通
今天遇到了一个问题,就是让Winform中的事件提前运行的问题,下面我给出解决方案
Main函数
using System; using System.Windows.Forms; namespace FormLoadCompletedDemo { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } }
using System; using System.Windows.Forms; namespace FormLoadCompletedDemo { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void ShowChildForm(ChildForm.LoadStyle ls) { ChildForm frm = new ChildForm(ls); frm.ShowDialog(); } private void btnLoad_Click(object sender, EventArgs e) { ShowChildForm(ChildForm.LoadStyle.OnLoad); } private void btnShown_Click(object sender, EventArgs e) { ShowChildForm(ChildForm.LoadStyle.OnShown); } private void btnShownDoEvents_Click(object sender, EventArgs e) { ShowChildForm(ChildForm.LoadStyle.OnShownDoEvents); } private void btnChildUsingBase_Click(object sender, EventArgs e) { ChildFormUsingBase frm = new ChildFormUsingBase(); frm.ShowDialog(); } } }
namespace FormLoadCompletedDemo { partial class MainForm { /// <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.btnShown = new System.Windows.Forms.Button(); this.btnShownDoEvents = new System.Windows.Forms.Button(); this.btnLoad = new System.Windows.Forms.Button(); this.btnChildUsingBase = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnShown // this.btnShown.Location = new System.Drawing.Point(50, 49); this.btnShown.Name = "btnShown"; this.btnShown.Size = new System.Drawing.Size(193, 23); this.btnShown.TabIndex = 1; this.btnShown.Text = "Open Form Without DoEvents"; this.btnShown.UseVisualStyleBackColor = true; this.btnShown.Click += new System.EventHandler(this.btnShown_Click); // // btnShownDoEvents // this.btnShownDoEvents.Location = new System.Drawing.Point(50, 78); this.btnShownDoEvents.Name = "btnShownDoEvents"; this.btnShownDoEvents.Size = new System.Drawing.Size(193, 23); this.btnShownDoEvents.TabIndex = 2; this.btnShownDoEvents.Text = "Open Form *With* DoEvents"; this.btnShownDoEvents.UseVisualStyleBackColor = true; this.btnShownDoEvents.Click += new System.EventHandler(this.btnShownDoEvents_Click); // // btnLoad // this.btnLoad.Location = new System.Drawing.Point(50, 20); this.btnLoad.Name = "btnLoad"; this.btnLoad.Size = new System.Drawing.Size(193, 23); this.btnLoad.TabIndex = 0; this.btnLoad.Text = "Do processing in Load event"; this.btnLoad.UseVisualStyleBackColor = true; this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); // // btnChildUsingBase // this.btnChildUsingBase.Location = new System.Drawing.Point(50, 138); this.btnChildUsingBase.Name = "btnChildUsingBase"; this.btnChildUsingBase.Size = new System.Drawing.Size(193, 23); this.btnChildUsingBase.TabIndex = 3; this.btnChildUsingBase.Text = "Open Form derived from BaseForm"; this.btnChildUsingBase.UseVisualStyleBackColor = true; this.btnChildUsingBase.Click += new System.EventHandler(this.btnChildUsingBase_Click); // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 183); this.Controls.Add(this.btnChildUsingBase); this.Controls.Add(this.btnLoad); this.Controls.Add(this.btnShownDoEvents); this.Controls.Add(this.btnShown); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "FormLoadCompleteDemo"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button btnShown; private System.Windows.Forms.Button btnShownDoEvents; private System.Windows.Forms.Button btnLoad; private System.Windows.Forms.Button btnChildUsingBase; } }
Children form
using System; using System.Windows.Forms; namespace FormLoadCompletedDemo { public partial class ChildForm : Form { public enum LoadStyle { OnLoad, OnShown, OnShownDoEvents } private LoadStyle _ls; public ChildForm(LoadStyle ls) { InitializeComponent(); _ls = ls; } private void ChildForm_Load(object sender, EventArgs e) { if (_ls == LoadStyle.OnLoad) LoadList(); } private void ChildForm_Shown(object sender, EventArgs e) { if (_ls == LoadStyle.OnShown) LoadList(); else if (_ls == LoadStyle.OnShownDoEvents) { Application.DoEvents(); LoadList(); } } private void LoadList() { this.Cursor = Cursors.WaitCursor; for (int l = 0; l < 50000; l++) this.listBox1.Items.Add("Item " + l.ToString()); this.Cursor = Cursors.Default; } private void ChildForm_FormClosed(object sender, FormClosedEventArgs e) { // Without the following, subsequent instances of this form would load // slower than the 1st call, distorting the time-delay of this demo. listBox1.Items.Clear(); GC.Collect(); } } }
namespace FormLoadCompletedDemo { partial class ChildForm { /// <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.listBox1 = new System.Windows.Forms.ListBox(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.comboBox2 = new System.Windows.Forms.ComboBox(); this.comboBox3 = new System.Windows.Forms.ComboBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.comboBox4 = new System.Windows.Forms.ComboBox(); this.comboBox5 = new System.Windows.Forms.ComboBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // listBox1 // this.listBox1.FormattingEnabled = true; this.listBox1.Location = new System.Drawing.Point(6, 59); this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(112, 134); this.listBox1.TabIndex = 0; // // comboBox1 // this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(6, 59); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(174, 21); this.comboBox1.TabIndex = 1; // // comboBox2 // this.comboBox2.FormattingEnabled = true; this.comboBox2.Location = new System.Drawing.Point(6, 86); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(174, 21); this.comboBox2.TabIndex = 2; // // comboBox3 // this.comboBox3.FormattingEnabled = true; this.comboBox3.Location = new System.Drawing.Point(6, 113); this.comboBox3.Name = "comboBox3"; this.comboBox3.Size = new System.Drawing.Size(174, 21); this.comboBox3.TabIndex = 3; // // groupBox1 // this.groupBox1.Controls.Add(this.comboBox5); this.groupBox1.Controls.Add(this.comboBox4); this.groupBox1.Controls.Add(this.comboBox3); this.groupBox1.Controls.Add(this.comboBox1); this.groupBox1.Controls.Add(this.comboBox2); this.groupBox1.Location = new System.Drawing.Point(166, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(193, 199); this.groupBox1.TabIndex = 4; this.groupBox1.TabStop = false; this.groupBox1.Text = "These controls don\'t fully render in form_Shown() unless you call DoEvents() *bef" + "ore* loading listBox1"; // // groupBox2 // this.groupBox2.Controls.Add(this.listBox1); this.groupBox2.Location = new System.Drawing.Point(12, 12); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(135, 199); this.groupBox2.TabIndex = 5; this.groupBox2.TabStop = false; this.groupBox2.Text = "This list is loaded with 50k items in order to delay the initial rendering of the" + " form."; // // comboBox4 // this.comboBox4.FormattingEnabled = true; this.comboBox4.Location = new System.Drawing.Point(6, 140); this.comboBox4.Name = "comboBox4"; this.comboBox4.Size = new System.Drawing.Size(174, 21); this.comboBox4.TabIndex = 4; // // comboBox5 // this.comboBox5.FormattingEnabled = true; this.comboBox5.Location = new System.Drawing.Point(6, 167); this.comboBox5.Name = "comboBox5"; this.comboBox5.Size = new System.Drawing.Size(174, 21); this.comboBox5.TabIndex = 5; // // ChildForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(374, 224); this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox2); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ChildForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "ChildForm"; this.Load += new System.EventHandler(this.ChildForm_Load); this.Shown += new System.EventHandler(this.ChildForm_Shown); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ChildForm_FormClosed); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.ComboBox comboBox2; private System.Windows.Forms.ComboBox comboBox3; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.ComboBox comboBox5; private System.Windows.Forms.ComboBox comboBox4; } }
using System; using System.Windows.Forms; namespace FormLoadCompletedDemo { public partial class ChildFormUsingBase : BaseForm { public ChildFormUsingBase() { InitializeComponent(); } private void ChildFormUsingBase_LoadCompleted() { this.Cursor = Cursors.WaitCursor; for (int l = 0; l < 50000; l++) this.listBox1.Items.Add("Item " + l.ToString()); this.Cursor = Cursors.Default; } private void ChildFormUsingBase_FormClosed(object sender, FormClosedEventArgs e) { // Without the following, subsequent instances of this form would load // slower than the 1st call, distorting the time-delay of this demo. listBox1.Items.Clear(); GC.Collect(); } } }
namespace FormLoadCompletedDemo { partial class ChildFormUsingBase { /// <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.listBox1 = new System.Windows.Forms.ListBox(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.comboBox2 = new System.Windows.Forms.ComboBox(); this.comboBox3 = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // listBox1 // this.listBox1.FormattingEnabled = true; this.listBox1.Location = new System.Drawing.Point(12, 12); this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(120, 95); this.listBox1.TabIndex = 0; // // comboBox1 // this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(192, 21); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(121, 21); this.comboBox1.TabIndex = 1; // // comboBox2 // this.comboBox2.FormattingEnabled = true; this.comboBox2.Location = new System.Drawing.Point(192, 48); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(121, 21); this.comboBox2.TabIndex = 2; // // comboBox3 // this.comboBox3.FormattingEnabled = true; this.comboBox3.Location = new System.Drawing.Point(192, 75); this.comboBox3.Name = "comboBox3"; this.comboBox3.Size = new System.Drawing.Size(121, 21); this.comboBox3.TabIndex = 3; // // label1 // this.label1.Location = new System.Drawing.Point(22, 129); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(277, 35); this.label1.TabIndex = 4; this.label1.Text = "This form performs post-Shown() processing by attaching to BaseForm\'s LoadComplet" + "ed() event"; // // ChildFormUsingBase // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(328, 187); this.Controls.Add(this.label1); this.Controls.Add(this.comboBox3); this.Controls.Add(this.comboBox2); this.Controls.Add(this.comboBox1); this.Controls.Add(this.listBox1); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ChildFormUsingBase"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "ChildFormUsingBase"; this.LoadCompleted += new FormLoadCompletedDemo.BaseForm.LoadCompletedEventHandler(this.ChildFormUsingBase_LoadCompleted); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ChildFormUsingBase_FormClosed); this.ResumeLayout(false); } #endregion private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.ComboBox comboBox2; private System.Windows.Forms.ComboBox comboBox3; private System.Windows.Forms.Label label1; } }
下面给出工程,有问题请联系我哦
- FormLoadCompletedDemo.zip (12.7 KB)
- 下载次数: 1
发表评论
-
减少winform的内存使用量
2013-06-01 06:49 1139今天看到有趣的代码,功能主要是减少winform的内存使用量。 ... -
C# Timer运行时,系统时间修改
2012-10-19 15:55 2874今天遇到一个问题: C# Time 运行的时候,将系统时间修 ... -
C# 一步一步的开始
2012-09-09 11:02 0------------------------------- ... -
C# 书写window简单服务
2012-03-30 19:59 1238代码如下: using System.Co ... -
手工添加window 服务依赖
2012-03-29 15:11 1917这里是bat文件 复制就可以添加 ... -
Services do not start and Event ID 7022
2012-03-29 15:07 1391今天遇到一个问题 具体的如题 解决方案: ... -
C# 读2007Excel文件
2012-03-27 13:51 2380今天遇到一个问题: C# ... -
C# 胡乱实现,程序 占用CPU50%
2012-02-28 07:05 3700今天早上看到了编程之美,我很兴奋,大早上看书,有吗? 有木有? ... -
IIS not work because of Com+ Application error or IWAM user not have password
2012-02-24 16:19 1745今天遇到了一个问题。XP的IIS 5.1 安装成功后会出现: ... -
IIS 7.0 HTTP Error 403.14
2012-02-23 13:09 1488刚才碰到一个问题:如题 下面是解决方案: 方法 ... -
C# Chart详细解析(待)
2012-02-07 19:25 54912一年有过去了, 很长时间也没有写什么文章了,准确的说是2个月, ... -
ProcessBar 2种经典实现
2011-12-15 14:05 1137我今天实装了ProcessBar 的两种实现方式 下面 ... -
using C# modify app.config in the run time
2011-12-13 11:19 1330今天在印度的网站上发现一个很经典的代码,也对比了国内的网站的答 ... -
winform 方向键焦点丢失问题(keydown event not work)
2011-12-10 11:47 1935在项目中遇到了,方向键不能被keydown event 捕捉的 ... -
Windows Install SQL Manager Error
2011-11-21 09:52 1070在安装SQL Manager的时候会出现异常,是由于操作系统的 ... -
C# 文件Copy 不包含.svn文件
2011-11-18 11:48 1826今天遇到了C#文件copy的问题 现在写出了解决方案 ... -
实现winform 代码导入dll
2011-11-14 14:48 1487代码如下: [DllImport(" ... -
C# winform 应用程序只打开一次(实现)
2011-11-14 13:43 7008winform 有的时候只能打开一次,下一次不要打开的应用 ... -
.net 3.5 Form Chart 解决方案
2011-11-12 16:49 1704刚刚写了一篇关于自己生活的文章,下面写下,最近我一直在做个项目 ... -
Window Form所有组件按主Form扩大
2011-11-08 13:08 1285今天遇到了Form 扩大到问题,写下了如下代码,希望对大家有用 ...
相关推荐
WinForm常用事件.rar WinForm常用事件.rar WinForm常用事件.rar WinForm常用事件.rar
C#WinForm窗体事件执行次序(较完整版)
winform委托和事件经典例子,委托 和 事件 winform 传值 子传父 父传子
winform程序防止重复运行
代码已封装,仅一个方法,调用即可使想要的窗体或者控件变得不在触发事件,直接穿透到电脑桌面。适用于做屏保或者截屏或者一些小工具程序。
\WINFORM\C# WinForm 最大化、最小化、关闭按钮事件的拦截
因为业务的需要,有时会使用到自定义运行时窗体设计器Runtime FormDesigner,实现的功能,就是IDE设计器的简化。设想一下,如果可以在程序运行时,再设计一个Form,然后编译代码,那是多么强大呀。
C# 只能运行一个winForm进程 C# 只能运行一个winForm进程 C# 只能运行一个winForm进程
通过鼠标点击事件控制panel的自动滚动条移动,实现在触摸屏上的手指拖动效果
C# Winform 自动运行 不用输入密码登录进入桌面可以运行的程序。.Net Framework4.5桌面程序
VB.NET Winform窗口后台运行+防多开+开机后台自动启动示例 可用于制作一个开启自动启动的后台运行程序,并且自带窗口可唤出显示
winform键盘输入事件和鼠标滚轮事件的捕捉与重写
鼠标在PicureBox中连续点击,将所点击的点用线条连接起来; 鼠标进入PicureBox区域时在窗口下方显示鼠标的坐标信息; 在窗口右边的TextBox控件中显示鼠标相关的事件日志。
C# 图片浏览器 winform实例 不能运行我是猪。双击控件就可以。
C#委托事件,窗体之间可以传值 是两个可以看到效果的实例,也是基本思路,其他想怎么做只要稍微做一下扩展就可以了
C# WinForm 用MenuStrip动态生成菜单并动态加载事件
C# I\O文件输入输出 winform实例 不能运行我是猪。文件夹的创建,删除。文件的写入和读取。
C# winform 单击与双击事件同时存在例子 在wiform中单击与双击事件是不可以同时存在的。
WinForm皮肤WinForm皮肤WinForm皮肤WinForm皮肤