Winfrom如何能加快界面的加载速度
窗体设计器生成的代码
- C# code
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label6; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Label label7; private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.Label label8; private System.Windows.Forms.PictureBox pictureBox3; private System.Windows.Forms.Label label9; private System.Windows.Forms.PictureBox pictureBox4; private System.Windows.Forms.Label label10; private System.Windows.Forms.PictureBox pictureBox5; private System.Windows.Forms.Label label11; private System.Windows.Forms.PictureBox pictureBox6; private System.Windows.Forms.Label label12; private System.Windows.Forms.PictureBox pictureBox7; private System.Windows.Forms.Label label13; private System.Windows.Forms.PictureBox pictureBox8; private System.Windows.Forms.Label label14; private System.Windows.Forms.PictureBox pictureBox9; private System.Windows.Forms.Label label15; private System.Windows.Forms.PictureBox pictureBox10; private System.Windows.Forms.Label label16; private System.Windows.Forms.PictureBox pictureBox11; private System.Windows.Forms.Label label17; private System.Windows.Forms.Label label18; private System.Windows.Forms.Label label19; private System.Windows.Forms.Label label20; private System.Windows.Forms.Label label21; private System.Windows.Forms.PictureBox pictureBox12; private System.Windows.Forms.PictureBox pictureBox13; private System.Windows.Forms.PictureBox pictureBox14; private System.Windows.Forms.PictureBox pictureBox15; private System.Windows.Forms.PictureBox pictureBox16; private System.Windows.Forms.Label label22; private System.Windows.Forms.Label label23; private System.Windows.Forms.Label label24; private System.Windows.Forms.Label label25; private System.Windows.Forms.Label label26; private System.Windows.Forms.PictureBox pictureBox17; private System.Windows.Forms.PictureBox pictureBox18; private System.Windows.Forms.PictureBox pictureBox19; private System.Windows.Forms.PictureBox pictureBox20; private System.Windows.Forms.PictureBox pictureBox21; private System.Windows.Forms.Label label27; private System.Windows.Forms.Label label28; private System.Windows.Forms.Label label29; private System.Windows.Forms.Label label30; private System.Windows.Forms.Label label31; private System.Windows.Forms.PictureBox pictureBox22; private System.Windows.Forms.PictureBox pictureBox23; private System.Windows.Forms.PictureBox pictureBox24; private System.Windows.Forms.PictureBox pictureBox25; private System.Windows.Forms.PictureBox pictureBox26; private System.Windows.Forms.Label label1;
示例控件的详情设计情况
- C# code
// // label6 // this.label6.AutoSize = true; this.label6.BackColor = System.Drawing.Color.Transparent; this.label6.Cursor = System.Windows.Forms.Cursors.Hand; this.label6.Font = new System.Drawing.Font("宋体", 13F, System.Drawing.FontStyle.Bold); this.label6.ForeColor = System.Drawing.Color.White; this.label6.Location = new System.Drawing.Point(66, 167); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(76, 18); this.label6.TabIndex = 2; this.label6.Text = "御 湾"; this.label6.Click += new System.EventHandler(this.label6_Click); // // pictureBox1 // this.pictureBox1.BackColor = System.Drawing.Color.Transparent; this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage"))); this.pictureBox1.Location = new System.Drawing.Point(47, 170); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(13, 13); this.pictureBox1.TabIndex = 3; this.pictureBox1.TabStop = false;
界面上有这些控件,运行后发现要加载5秒钟才能把全部控件显示出来,
请问有什么办法能提高下加载速度吗?
[解决办法]
具体问题具体分析,比如绘制时如果某个控件加载速度很慢,就把它放到单独的线程去加载。
如果想偷懒,可以先不加载比较慢的控件,有用户点击确认时在加载。
[解决办法]
[解决办法]
[解决办法]
方法1 异步加载窗体控件
方法2 把这个窗体单例 (单例后就不要close了,只 show和 hide)
[解决办法]