C#学习教程:在继承窗体上打开设计器时出错这是我从前雇员那里接手的一个项目,但有些移动设备运行的是编译版本,所以我认为它应该可以打开。我有正确版本的VS(2008)并尝试清理解决方案并重建解决方案。在部署解决方案时,它就像一个魅力。一旦我尝试进入继承表的设备,我就会收到以下错误:为了防止在加载设计器之前可能丢失数据,必须解决以下错误:对象引用未设置为对象的实例。堆垛跟踪:atMyApp.frmBase.UpdateOnline()inC:UsersCorneDocumentsVisualStudio2008ProjectsTestMyAppMyAppfrmBase.cs:line35atMyApp.frmBase.frmBase_Load(Objectsender,EventArgse)inC:UsersCorneDocumentsVisualStudio2008ProjectsTestWindowsMyAppMyApplineBase3.csSystem.frmBase_Load(Objectsender,EventArgse).Forms.Form.OnLoad(EventArgse)在System.Windows.Forms.Form.OnCreateControl()在System.Windows.Forms.Control.CreateControl(BooleanfIgnoreVisible)在System.Windows.Forms.Control.CreateControl()在System.Windows.Forms.Control.SetVisibleCore(布尔值)在System.Windows.Forms.Form.SetVisibleCore(布尔值)在System.Windows.Forms.Control.set_Visible(布尔值)在System.Windows.Forms.Design.DesignerFrame.Initialize(控制视图)在System.Windows.Forms.Design.DocumentDesig在System.Windows.Forms.Design.FormDocumentDesigner.Initialize(IComponent组件)在System.ComponentModel.Design.DesignerHost.AddToContainerPostProcess(IComponent组件,字符串名称,IContainercontainerToAddTo)在System.ComponentModel.Design。DesignerHost.Add(IComponent组件,字符串名称)在System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(类型componentType,字符串名称)在System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(类型类型,ICollection参数,字符串名称,布尔addToContainer)在System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(类型类型,ICollection参数,字符串名称,布尔addToContainer)在System.ComponentModel。设计.序列化.TypeCodeDomSerializer.反序列化(IDesignerSerializationManager管理器,CodeTypeDeclaration声明)在System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager管理器)在Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager序列化管理器)在Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32fReload)从stacktrace中可以清楚的看到底层窗体的Load事件处理程序正在运行并抛出异常这是正常的,对于基本窗体这样的事件因为Load和Paint也在设计时运行。它提供所见即所得的设计器视图。但是,如果该代码只能在运行时正确运行,那就很糟糕了。Control.DesignMode属性旨在为您提供一种检查类中的代码是否在设计时运行的方法。遗憾的是,它不适用于CF,因此需要采用不同的方法。魔咒长这样:以上是C#学习教程:在继承窗体上打开设计器时出错全部内容分享,如果对大家有用需要详细了解C#学习教程,希望大家付费更多关注—privatevoidfrmBase_Load(objectsender,EventArgse){if(this.Site==null||!this.Site.DesignMode){//不在设计模式下,可以做危险的事情...this.UpdateOnline();}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
