Click here to Skip to main content
15,894,343 members
Articles / Programming Languages / C#

Immediate Display of WinForms using the Shown() Event

Rate me:
Please Sign up or sign in to vote.
4.76/5 (63 votes)
12 Feb 2010CPOL6 min read 170.1K   3.3K   137  
How to cause a Winform (and all its child controls) to fully render before you do additional processing.
namespace FormLoadCompletedDemo
{
	partial class MainForm
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (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.btnShown = new System.Windows.Forms.Button();
			this.btnShownDoEvents = new System.Windows.Forms.Button();
			this.btnLoad = new System.Windows.Forms.Button();
			this.btnChildUsingBase = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnShown
			// 
			this.btnShown.Location = new System.Drawing.Point(50, 49);
			this.btnShown.Name = "btnShown";
			this.btnShown.Size = new System.Drawing.Size(193, 23);
			this.btnShown.TabIndex = 1;
			this.btnShown.Text = "Open Form Without DoEvents";
			this.btnShown.UseVisualStyleBackColor = true;
			this.btnShown.Click += new System.EventHandler(this.btnShown_Click);
			// 
			// btnShownDoEvents
			// 
			this.btnShownDoEvents.Location = new System.Drawing.Point(50, 78);
			this.btnShownDoEvents.Name = "btnShownDoEvents";
			this.btnShownDoEvents.Size = new System.Drawing.Size(193, 23);
			this.btnShownDoEvents.TabIndex = 2;
			this.btnShownDoEvents.Text = "Open Form *With* DoEvents";
			this.btnShownDoEvents.UseVisualStyleBackColor = true;
			this.btnShownDoEvents.Click += new System.EventHandler(this.btnShownDoEvents_Click);
			// 
			// btnLoad
			// 
			this.btnLoad.Location = new System.Drawing.Point(50, 20);
			this.btnLoad.Name = "btnLoad";
			this.btnLoad.Size = new System.Drawing.Size(193, 23);
			this.btnLoad.TabIndex = 0;
			this.btnLoad.Text = "Do processing in Load event";
			this.btnLoad.UseVisualStyleBackColor = true;
			this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
			// 
			// btnChildUsingBase
			// 
			this.btnChildUsingBase.Location = new System.Drawing.Point(50, 138);
			this.btnChildUsingBase.Name = "btnChildUsingBase";
			this.btnChildUsingBase.Size = new System.Drawing.Size(193, 23);
			this.btnChildUsingBase.TabIndex = 3;
			this.btnChildUsingBase.Text = "Open Form derived from BaseForm";
			this.btnChildUsingBase.UseVisualStyleBackColor = true;
			this.btnChildUsingBase.Click += new System.EventHandler(this.btnChildUsingBase_Click);
			// 
			// MainForm
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(292, 183);
			this.Controls.Add(this.btnChildUsingBase);
			this.Controls.Add(this.btnLoad);
			this.Controls.Add(this.btnShownDoEvents);
			this.Controls.Add(this.btnShown);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "FormLoadCompleteDemo";
			this.ResumeLayout(false);

		}

		#endregion

		private System.Windows.Forms.Button btnShown;
		private System.Windows.Forms.Button btnShownDoEvents;
		private System.Windows.Forms.Button btnLoad;
		private System.Windows.Forms.Button btnChildUsingBase;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I can type "while" and "for" very quickly

Comments and Discussions