我有一个Windows应用程序,它在应用程序运行时有效,但在设计视图中,OnLoad事件中的代码由于许多原因而崩溃。有没有办法做这样的事情:
private void WindowsForm_OnLoad(object sender, EventArgs e)
{
if (IsDesignView())
{
// some code that breaks in design view but works normally
}
答案 0 :(得分:3)
从Component继承了DesignMode属性。
if(!this.DesignMode) {
// Your stuff...
}
虽然有更好的方法可以做到这一点,因为如果我没记错的话,有时可能会出现DesignMode
属性的问题。我想我在某个地方有一些代码,让我找到它。
DesignMode
的一些缺点,以及特定问题的解决方法。但是,这个问题不会影响你想要做的事情,看起来不像,但无论如何都要注意它。
答案 1 :(得分:0)
是的,请使用:
if (!this.DesignMode)
答案 2 :(得分:0)
您可以查看表单的DesignMode属性。
if (!this.DesignMode)
{
// Include code that breaks the designer here...
}