您的位置:首页 > 其它

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

2007-06-23 08:44 537 查看
减少方法调用




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


原文地址:http://www.cnblogs.com/upto/archive/2007/01/31/netcf-improve-form-load-perf.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: