Showing posts with label Windows Forms. Show all posts
Showing posts with label Windows Forms. Show all posts

Friday, September 08, 2006

DesignMode and Checking Design Mode on a WinForm

DesignMode checking can be troublesome with form inheritance. An example would be a base form has an OnLoad that does something

private void OnLoad(object sender, EventArgs e)
{
if (!DesignMode)
{
//Do something here.
}
}


Where the trouble starts is when the derived form is loaded in the visual studio designer. DesignMode solving to true in the base form is not always guaranteed, therefore an acceptable solution would be the following:

///
/// Indicates if the current view is being utilized in the VS.NET IDE or not.
///
public new bool DesignMode
{
get
{
return (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv");
}
}