提高.NET Compact Framework 1.0应用程序的窗体加载性能

减少方法调用
    this.textBox1.Location = new Point(10,20);
    
this.textBox1.Size = new Size(72,23);
换成
    this.textBox1.Bounds = new Rectangle(10,20,72,23);

不要把子控件加到父控件的Controls集合,通过Parent来控制
// Before optimization
// Create a new panel and textbox control

Panel panel1 = new Panel();
TextBox textBox1 
= new
 TextBox();
// Set the Text property of the TextBox control

textBox1.Text = "My Text";
// Add the TextBox to the Panel's control collection

panel1.Controls.Add(this.textBox1);
// Add the Panel to the Form's control collection

this.Controls.Add(panel1);
... 
// Add subsequent controls here
换成
// After optimization
// Create a new panel and textbox control

Panel panel1 = new Panel();
TextBox textBox1 
= new
 TextBox();
// Parent the Panel to the current Form

this.panel1.Parent = this;
// Parent the TextBox to the Panel

this.textBox1.Parent(this.panel1);
// Set the Text property of the TextBox control

textBox1.Text = "My Text";
... 
// Add subsequent controls here

听说使用这两个方法修改窗体设计器生成的代码后,可以提高55%的窗体加载性能。不过,这样修改后的窗体,是否还能再用窗体设计器编辑?有多少人愿意这样做?

参考:
改进基于 Microsoft .NET Framework 精简版应用程序窗体的加载性能
Improving Microsoft .NET Compact Framework-based Application Form Load Performance

posted @ 2007-01-31 12:27  黎波  阅读(3123)  评论(13编辑  收藏  举报