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”);
}
}
No comments yet. Be the first.
Leave a reply