减少方法调用
this.textBox1.Location=newPoint(10,20
);
this.textBox1.Size=newSize(72,23);
换成
this.textBox1.Bounds=newRectangle(10,20,72,23);
不要把子控件加到父控件的Controls集合,通过Parent来控制
//
Beforeoptimization
//Createanewpanelandtextboxcontrol
Panelpanel1=new
Panel();
TextBoxtextBox1=new
TextBox();
//SettheTextpropertyoftheTextBoxcontrol
textBox1.Text="MyText"
;
//AddtheTextBoxtothePanel'scontrolcollection
panel1.Controls.Add(this
.textBox1);
//AddthePaneltotheForm'scontrolcollection
this
.Controls.Add(panel1);
...//Addsubsequentcontrolshere
换成
//
Afteroptimization
//Createanewpanelandtextboxcontrol
Panelpanel1=new
Panel();
TextBoxtextBox1=new
TextBox();
//ParentthePaneltothecurrentForm
this.panel1.Parent=this
;
//ParenttheTextBoxtothePanel
this.textBox1.Parent(this
.panel1);
//SettheTextpropertyoftheTextBoxcontrol
textBox1.Text="MyText"
;
...//Addsubsequentcontrolshere
听说使用这两个方法修改窗体设计器生成的代码后,可以提高55%的窗体加载性能。不过,这样修改后的窗体,是否还能再用窗体设计器编辑?有多少人愿意这样做?
参考:
改进基于 Microsoft .NET Framework 精简版应用程序窗体的加载性能
Improving Microsoft .NET Compact Framework-based Application Form Load Performance
原文地址:http://www.cnblogs.com/upto/archive/2007/01/31/netcf-improve-form-load-perf.html
本文介绍通过减少方法调用及改变控件添加方式来优化.NET Framework精简版应用程序窗体加载性能的方法,实践表明这些优化能提升55%的加载速度。
100

被折叠的 条评论
为什么被折叠?



