How to detect that C# Windows Forms code is executed within Visual Studio?

后端 未结 8 1929
春和景丽
春和景丽 2020-11-29 23:46

Is there a variable or a preprocessor constant that allows to know that the code is executed within the context of Visual Studio?

8条回答
  •  清歌不尽
    2020-11-30 00:15

    The DesignMode property isn't always accurate. We have had use this method so that it works consistently:

        protected new bool DesignMode
        {
            get
            {
                if (base.DesignMode)
                    return true;
    
                return LicenseManager.UsageMode == LicenseUsageMode.Designtime;
            }
        }
    

    The context of your call is important. We've had DesignMode return false in the IDE if running in an event under certain circumstances.

提交回复
热议问题