Error when opening designer on inherited form

前端 未结 2 1830
灰色年华
灰色年华 2021-02-10 01:09

I am having trouble opening an inherited form in a Windows CE application. This is a project that I am taking over from a ex-employee, but there is compiled versions running on

2条回答
  •  天涯浪人
    2021-02-10 01:49

    You can clearly see from the stack trace that your base form's Load event handler is running and throwing an exception. This is normal, events in the base form like Load and Paint run at design time as well. It provides the WYSIWYG designer view. This however goes poorly if that code can only work properly at runtime.

    The Control.DesignMode property was meant to provide you with a way to check if the code in the the class is operating at design time. Unfortunately it is not available in CF so a different approach is needed. The magic incantation looks like this:

        private void frmBase_Load(object sender, EventArgs e) {
            if (this.Site == null || !this.Site.DesignMode) {
                // Not in design mode, okay to do dangerous stuff...
                this.UpdateOnline();
            }
        }
    

提交回复
热议问题