VS开发过程中,如果我们使用了处定义控件,在设计时会引发一些事件,如果不想被执行,可以判断一下如果是在设计模式下就不要运行。
public static bool IsDesignMode()
{
bool returnFlag = false;
#if DEBUG
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
returnFlag = true;
}
else if (Process.GetCurrentProcess().ProcessName == "devenv")
{
returnFlag = true;
}
#endif
return returnFlag;
}
在Visual Studio(VS)开发过程中,如果自定义控件在设计时触发事件,可以通过判断当前是否处于设计模式来阻止执行。IsDesignMode()函数通过检查Debug模式、LicenseManager的UsageMode或当前进程名称(devenv)来确定是否在设计环境中,从而避免不必要的运行。
1213

被折叠的 条评论
为什么被折叠?



