Hi Stephen,
Then, how about drawing in the OnPaintBackground method? Is it helpful?
I must say there's not many way to improve the painting speed at first time.
Maybe you should try developing your application using Visual C++ or etc,
if the painting speed is
really important.
Thanks!
Kind regards,
Ying-Shen Yu [MS]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| From: "Stephen" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]> <
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: Controls draw slow on forms
| Date: Wed, 3 Sep 2003 18:42:11 -0400
| Lines: 215
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: c-66-177-177-97.se.client2.attbi.com 66.177.177.97
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51587
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Just because it looks unprofessional coming together piece-by-piece, and
if
| I can notice it on my system it will be worse on slower systems the
| application is designed to target.
|
| | > Hi Stephen,
| > You may try overridding the OnPaintBackground method of your form,
and
| > draw your images in it, this will reduce the delay of displaying image,
| but
| > you must postion it by code, and you shouldn't draw large images or your
| > form might get flicker when moving from the screen edge, however 180x180
| is
| > acceptable in my mind. I feel sorry I haven't find a better way to make
| the
| > controls draw faster.
| > In addition could you tell me why you need draw the form quickly at
| first
| > time? thanks!
| >
| > Here is an simple example:
| > using System;
| > using System.Drawing;
| > using System.Collections;
| > using System.ComponentModel;
| > using System.Windows.Forms;
| > using System.Diagnostics;
| >
| > namespace Drag_n_Drop
| > {
| > /// <summary>
| > /// Summary description for Form2.
| > /// </summary>
| > public class Form2 : System.Windows.Forms.Form
| > {
| > private System.Windows.Forms.Button button1;
| > private System.Windows.Forms.Button button2;
| > private System.Windows.Forms.Button button3;
| > /// <summary>
| > /// Required designer variable.
| > /// </summary>
| > private System.ComponentModel.Container components = null;
| > private Bitmap bmp = null;
| > public Form2()
| > {
| > InitializeComponent();
| > // Changed it to your own
| image
| > file
| > bmp = new Bitmap(@"DJAqua.JPG");
| > }
| >
| > /// <summary>
| > /// Clean up any resources being used.
| > /// </summary>
| > protected override void Dispose( bool disposing )
| > {
| > if( disposing )
| > {
| > if(components != null)
| > {
| > components.Dispose();
| > }
| > }
| > base.Dispose( disposing );
| > }
| >
| > #region Windows Form Designer generated code
| > /// <summary>
| > /// Required method for Designer support - do not modify
| > /// the contents of this method with the code editor.
| > /// </summary>
| > private void InitializeComponent()
| > {
| > this.button1 = new System.Windows.Forms.Button();
| > this.button2 = new System.Windows.Forms.Button();
| > this.button3 = new System.Windows.Forms.Button();
| > this.SuspendLayout();
| > //
| > // button1
| > //
| > this.button1.Location = new System.Drawing.Point(352, 88);
| > this.button1.Name = "button1";
| > this.button1.TabIndex = 0;
| > this.button1.Text = "Close";
| > this.button1.Click += new System.EventHandler(this.button1_Click);
| > //
| > // button2
| > //
| > this.button2.Location = new System.Drawing.Point(352, 24);
| > this.button2.Name = "button2";
| > this.button2.TabIndex = 1;
| > this.button2.Text = "button2";
| > //
| > // button3
| > //
| > this.button3.Location = new System.Drawing.Point(352, 56);
| > this.button3.Name = "button3";
| > this.button3.TabIndex = 2;
| > this.button3.Text = "button3";
| > //
| > // Form2
| > //
| > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
| > this.ClientSize = new System.Drawing.Size(432, 205);
| > this.Controls.Add(this.button3);
| > this.Controls.Add(this.button2);
| > this.Controls.Add(this.button1);
| > this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
| > this.MaximizeBox = false;
| > this.MinimizeBox = false;
| > this.Name = "Form2";
| > this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
| > this.Text = "Form2";
| > this.ResumeLayout(false);
| >
| > }
| > #endregion
| >
| > private void button1_Click(object sender, System.EventArgs e)
| > {
| > Close();
| > }
| >
| > protected override void OnPaintBackground(PaintEventArgs e)
| > {
| > base.OnPaintBackground (e);
| > //draw your image here
| > e.Graphics.DrawImage(bmp,new Rectangle(5,5,180,180),
| > new Rectangle(0,0,180,180),GraphicsUnit.Pixel);
| > }
| >
| > }
| > }
| >
| >
| > Kind regards,
| >
| > Ying-Shen Yu [MS]
| > Microsoft Support Engineer
| >
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| > You assume all risk for your use. 2001 Microsoft Corporation. All
rights
| > reserved.
| > --------------------
| > | From: "Stephen" <
[email protected]>
| > | References: <
[email protected]>
| > <
[email protected]>
| > <
[email protected]> <
[email protected]>
| > | Subject: Re: Controls draw slow on forms
| > | Date: Tue, 2 Sep 2003 01:06:29 -0400
| > | Lines: 35
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <
[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.windowsforms
| > | NNTP-Posting-Host: c-66-177-177-97.se.client2.attbi.com 66.177.177.97
| > | Path:
| >
|
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
| > phx.gbl!TK2MSFTNGP10.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| > microsoft.public.dotnet.framework.windowsforms:51436
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
| > |
| > | I ngen'ed my exe and ran it, no difference. So I started looking at
the
| > | files (ngen'ed one and original exe), both have all my variable and
| class
| > | names blatantly visible just by opening exe in notepad. I ngen'ed
again
| > to
| > | make sure and it said "up to date." I ran comp.exe on them and they
are
| > | identical. I thought this changed code into native code?? Even if I
| was
| > | wrong, shouldn't it do SOMEthing?
| > |
| > | Stephen
| > |
| > | | > | > > Setting the Image property to a file at design-time
| > | > > automatically creates a resource file for the form and
| > | > > the code to extract the image from it, so it is already
| > | > > reading from a resource file.
| > | >
| > | > I think Ying-Shen was referring to a Windows resource, not a .NET
| > | > resource. Windows resources are harder to work with from .NET, but
| they
| > | > would quite likely be faster, since there's less overhead and
they're
| > | > already in native Windows format.
| > | >
| > | > Anyway, I suspect that the Visual Studio about box either (1) isn't
| > | > written in .NET, or (2) is pre-compiled to native code with ngen, so
| it
| > | > doesn't have to wait for JIT compilation. You could try using ngen
on
| > | > your app and see if that helps you out.
| > | >
| > | > Also, is your About box the first place your app ever shows a Label
or
| a
| > | > LinkLabel? You might see if you can show one of each sometime
before
| > | > the About box ever appears, so they're already JIT-compiled by the
| time
| > | > your dialog is shown. If JIT-compile time is the issue, then
showing
| > | > one of each beforehand should take care of it. (This probably
| wouldn't
| > | > matter if you used ngen.)
| > | >
| > |
| > |
| > |
| >
|
|
|