I have a user control that I'm building. It's purpose is to display the status of a class to the user. Obviously, this does not matter, and will slow things down when the control runs in the IDE, as it does as soon as you add it to a form.
One way to work around this would be to have the control created and added to the controls collection of the form at run-time. But this seems less than perfect.
Is there a way to set a flag in the control so that it can skip certain sections of code based on how it is running?
p.s. I'm using C# and VS 2008
public static bool IsInRuntimeMode( IComponent component ) {
bool ret = IsInDesignMode( component );
return !ret;
}
public static bool IsInDesignMode( IComponent component ) {
bool ret = false;
if ( null != component ) {
ISite site = component.Site;
if ( null != site ) {
ret = site.DesignMode;
}
else if ( component is System.Windows.Forms.Control ) {
IComponent parent = ( (System.Windows.Forms.Control)component ).Parent;
ret = IsInDesignMode( parent );
}
}
return ret;
}
I found this answer on another post and it seems to be easier and working better for my situation.
Detecting design mode from a Control's constructor
using System.ComponentModel;
if (LicenseManager.UsageMode == LicenseUsageMode.Runtime)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With