How to entertain the user during a slow.. InitializeComponent()

  • Thread starter Thread starter Fulcrum
  • Start date Start date
F

Fulcrum

My program has 4 tabs with a few usercontrols that each have a lot of
controls on them. Added to that a few oleDb database connections etc.
Because of this the program spends a lot of time during
InitializeComponent() (>30sec on a P3-900MHz) I would like to display a
"splash" screen that displays the progress of InitializeComponent(). I'd
rather not edit the source of the InitializeComponent method, because Visual
Studio .NET plays around in it.

Right now I use a progressBar that slowly fills using a timer event on the
splash Form, but there is no real relation with the progress of
InitialializeComponent on the main Form.

I would really like to get some tips on alternative solutions to this
problem.

Thanks in advance for your time!
 
Hi,

You can use a splash screen, here is some code that I'm using, you could
also make a google search

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

//You create the form in the Main function():
[STAThread]

static void Main()

{

splashform = new splash();

Application.Run(new Form1());

}


//You close it after the InitializeComponent () :
splashform.CloseIt();



//This is the splash form, I'm using an image on a borderless form
public class splash : System.Windows.Forms.Form

{

private System.Windows.Forms.PictureBox pictureBox1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

DateTime time;

public splash()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

Show();

time = DateTime.Now;

Application.DoEvents();

}

public void CloseIt()

{

TimeSpan T = DateTime.Now - time;

if (T.Milliseconds<3000)

System.Threading.Thread.Sleep(3000-T.Milliseconds);

this.Close();

}

/// <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()

{

System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(splash));

this.pictureBox1 = new System.Windows.Forms.PictureBox();

this.SuspendLayout();

//

// pictureBox1

//

this.pictureBox1.Image =
((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));

this.pictureBox1.Location = new System.Drawing.Point(0, 0);

this.pictureBox1.Name = "pictureBox1";

this.pictureBox1.Size = new System.Drawing.Size(376, 208);

this.pictureBox1.TabIndex = 0;

this.pictureBox1.TabStop = false;

//

// splash

//

this.AutoScale = false;

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.BackColor = System.Drawing.Color.White;

this.ClientSize = new System.Drawing.Size(376, 205);

this.ControlBox = false;

this.Controls.Add(this.pictureBox1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;

this.MaximizeBox = false;

this.MinimizeBox = false;

this.Name = "splash";

this.ShowInTaskbar = false;

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.TopMost = true;

this.ResumeLayout(false);

}

#endregion

}
 
Back
Top