Click here to Skip to main content
15,886,799 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 169.7K   3.3K   137  
How to cause a Winform (and all its child controls) to fully render before you do additional processing.
using System;
using System.Windows.Forms;

namespace FormLoadCompletedDemo
{
	public partial class ChildFormUsingBase : BaseForm
	{
		public ChildFormUsingBase()
		{
			InitializeComponent();
		}

		private void ChildFormUsingBase_LoadCompleted()
		{
			this.Cursor = Cursors.WaitCursor;

			for (int l = 0; l < 50000; l++)
				this.listBox1.Items.Add("Item " + l.ToString());

			this.Cursor = Cursors.Default;
		}

		private void ChildFormUsingBase_FormClosed(object sender, FormClosedEventArgs e)
		{
			// Without the following, subsequent instances of this form would load
			//  slower than the 1st call, distorting the time-delay of this demo.
			listBox1.Items.Clear();
			GC.Collect();

		}
	}
}

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