- 浏览: 695706 次
- 性别:
- 来自: 沈阳
文章分类
- 全部博客 (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 1217今天看到有趣的代码,功能主要是减少winform的内存使用量。 ... -
C# Timer运行时,系统时间修改
2012-10-19 15:55 2945今天遇到一个问题: C# Time 运行的时候,将系统时间修 ... -
C# 一步一步的开始
2012-09-09 11:02 0------------------------------- ... -
C# 书写window简单服务
2012-03-30 19:59 1291代码如下: using System.Co ... -
手工添加window 服务依赖
2012-03-29 15:11 1960这里是bat文件 复制就可以添加 ... -
Services do not start and Event ID 7022
2012-03-29 15:07 1422今天遇到一个问题 具体的如题 解决方案: ... -
C# 读2007Excel文件
2012-03-27 13:51 2429今天遇到一个问题: C# ... -
C# 胡乱实现,程序 占用CPU50%
2012-02-28 07:05 3789今天早上看到了编程之美,我很兴奋,大早上看书,有吗? 有木有? ... -
IIS not work because of Com+ Application error or IWAM user not have password
2012-02-24 16:19 1793今天遇到了一个问题。XP的IIS 5.1 安装成功后会出现: ... -
IIS 7.0 HTTP Error 403.14
2012-02-23 13:09 1529刚才碰到一个问题:如题 下面是解决方案: 方法 ... -
C# Chart详细解析(待)
2012-02-07 19:25 55073一年有过去了, 很长时间也没有写什么文章了,准确的说是2个月, ... -
ProcessBar 2种经典实现
2011-12-15 14:05 1172我今天实装了ProcessBar 的两种实现方式 下面 ... -
using C# modify app.config in the run time
2011-12-13 11:19 1368今天在印度的网站上发现一个很经典的代码,也对比了国内的网站的答 ... -
winform 方向键焦点丢失问题(keydown event not work)
2011-12-10 11:47 2009在项目中遇到了,方向键不能被keydown event 捕捉的 ... -
Windows Install SQL Manager Error
2011-11-21 09:52 1118在安装SQL Manager的时候会出现异常,是由于操作系统的 ... -
C# 文件Copy 不包含.svn文件
2011-11-18 11:48 1876今天遇到了C#文件copy的问题 现在写出了解决方案 ... -
实现winform 代码导入dll
2011-11-14 14:48 1548代码如下: [DllImport(" ... -
C# winform 应用程序只打开一次(实现)
2011-11-14 13:43 7088winform 有的时候只能打开一次,下一次不要打开的应用 ... -
.net 3.5 Form Chart 解决方案
2011-11-12 16:49 1770刚刚写了一篇关于自己生活的文章,下面写下,最近我一直在做个项目 ... -
Window Form所有组件按主Form扩大
2011-11-08 13:08 1319今天遇到了Form 扩大到问题,写下了如下代码,希望对大家有用 ...
相关推荐
6. **异常处理**:有效的数据验证能减少程序运行时的异常,因为输入错误会提前被捕捉到。如果输入不符合规则,控件可能会抛出异常,或者显示错误消息给用户。 7. **用户体验优化**:通过实时反馈,用户可以立即看到...
NGEN 则是在安装时提前生成本机代码,以提高应用程序的启动速度。 **2.13 .NET CLR 的内存管理机制** .NET Common Language Runtime (CLR) 负责管理内存分配和回收,使用自动垃圾回收机制来释放不再使用的对象所...
总的来说,WinForm的延时加载控件通过合理控制数据加载的时间点,提高了应用程序的运行效率,特别是在处理大数据量或复杂交互场景时。通过重写控件的特定方法、监听特定事件以及自定义数据绑定策略,开发者可以灵活...
可以考虑提前加载和缩放图像,减少运行时负担。 3. 系统性能:硬件配置较低的系统可能会遇到性能问题。优化代码、提高系统性能或使用更高效的图像处理库可能有所帮助。 总结来说,通过C#调用MATLAB绘图并在Winform...
.NET Framework和.NET Core提供了强大的反射机制,可以让我们在运行时检查和操作类型。在插件开发中,反射常用于实例化动态加载的插件类,调用其方法,甚至创建未提前知道类型的对象。 5. **依赖注入** 为了降低...
- JIT 编译与传统的提前编译 (Ahead-Of-Time Compilation, AOT) 不同,AOT 在程序编译阶段就已经完成了所有编译工作。 - 通过 JIT 编译,C# 程序可以在多种不同的硬件平台上高效运行,而无需为每个平台单独编译。 ...
4. **配合服务端合作**:服务端可以根据用户的设备特性、网络状况等信息,智能地决定哪些图片需要提前加载。 ### 五、实战案例——模仿京东懒加载 京东作为国内知名的电商平台,其图片懒加载策略值得学习。京东的...
在C#性能优化领域,开发者们常常关注如何提高代码运行效率、减少资源消耗以及提升应用程序的整体性能。本文将深入探讨C#中涉及的几个关键优化点,包括数据库优化、服务器优化、线程管理和内存管理。 首先,我们来看...
4. 应用程序启动过程中的其他因素:除了web service本身,WinForm应用程序在首次运行时也可能需要初始化各种组件、资源加载等,这些都可能导致整体启动时间变长。 5. Web service的网络配置和硬件性能:Web service...
对于winform应用来说,"dingshiqi-modify"可能包含一个图形用户界面(GUI),让用户直观地设置定时器参数,如提醒时间、提醒方式等。在WinForms中,我们可以使用DateTimePicker控件让用户选择提醒时间,CheckBox或...
在Android开发中,ListView是一个非常常见的组件...附带的文件"VirtualListView_Test"可能是用于测试和演示这些优化技术的代码实例,而".suo"和".sln"则是Visual Studio解决方案和配置文件,帮助开发者构建和运行项目。
本篇文章通过一个具体的C# Winform托盘程序案例,详细介绍了如何使用C#来开发一个托盘程序,包括托盘图标的初始化、上下文菜单的定义、事件处理以及显示和隐藏托盘图标等核心知识点。这些技术点不仅适用于本文中的...
同时,根据历史销售数据,系统可进行销售预测,帮助4S店提前规划库存和销售策略。 6. 售后服务管理:4S店的售后服务是客户满意度的重要来源。系统需包含预约管理、维修工单、配件管理等模块,确保服务流程顺畅,...
8. **设备管理**:集成设备管理系统,监控设备运行状态,预测故障,提前安排维修,减少停机时间。 9. **物料跟踪**:通过条形码或RFID技术,追踪物料从入库到出库的全程,确保物料流向的透明度。 10. **接口集成**...
开发者需要根据应用场景提前设定并录入这些命令词,例如“打开灯”、“关闭电视”等。 3. **录音与音频处理**:在用户说出命令词后,Demo会捕获音频数据,然后对其进行降噪、分割等预处理,确保语音信号的质量,...
5. **性能优化**:对于计算量大的表达式,引擎可能需要进行优化,例如,提前计算常量表达式,或者在构建AST时消除无用的操作。 在"ExpressionEngine1"这个压缩包中,很可能包含了实现上述功能的源代码。通过研究...
9. **后台管理**:提供给管理员的专用界面,用于监控系统运行情况,处理异常问题,以及执行高级操作。 10. **图书多条件搜索**:用户可以根据书名、作者、出版社等信息进行多条件搜索,快速找到目标图书。 11. **...
优化后的代码通过提前存储这两个值,减少了冗余计算。类似地,如果在方法中多次创建相同对象,如正则表达式,应当考虑将其声明为静态常量或局部变量,以便重用。 2. **避免不必要的对象实例化**:在`Check`方法的...
如果你在做的是一个较大的winform程序或者silverlight等客户端程序时就需要考虑提前编译了。.Net framework安装目录下(类似C:\Windows\Microsoft.NET\Framework\v4.0.30319)有一个ngen.exe工具,就是做这件事儿的...