提高.NET Compact Framework 1.0应用程序的窗体加载性能
减少方法调用
this.textBox1.Location=newPoint(10,20
);
this.textBox1.Size=newSize(72,23);
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
//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
//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