简体   繁体   English

带有继承的UserControls的Visual Studio 2008 IDE错误

[英]Visual Studio 2008 IDE errors with Inherited UserControls

have a really annoying time developing some code for a set of UserControls that utilize fairly rudimentary inheritance. 在为一组使用相当基本的继承的UserControl开发一些代码时,真是很烦人。 Basically, they are three different Detail Views which all inherit from a single Base Class which in turn Implements a Single Interface. 基本上,它们是三个不同的详细视图,它们均从单个基类继承,而基类又实现了一个接口。

Interface IBaseDetailView 接口IBaseDetailView

Class BaseDetailView : Implements IBaseDetailView 类BaseDetailView:实现IBaseDetailView

Class DetailView1 : Inherits BaseDetailView Class DetailView2 : Inherits BaseDetailView Class DetailView3 : Inherits BaseDetailView 类DetailView1:继承BaseDetailView类DetailView2:继承BaseDetailView类DetailView3:继承BaseDetailView

Then I have a Composite UserControl That adds the individual DetailViews 1-3 on a tab on the TabControl. 然后,我有一个复合用户控件,该控件在TabControl的选项卡上添加了各个DetailViews 1-3。

Pretty Simple stuff. 很简单的东西。 Everything compiles fine, All the UserControls are available in the toolbox and can be dragged and dropped onto any form. 一切都可以正常编译,所有用户控件都可以在工具箱中找到,并且可以拖放到任何表单上。 But there is one problem... 但是有一个问题...

They initially display and what not, but after compiling the form errors out with the infamous "Instance of object not set to reference" error. 它们最初显示什么,但不显示,但是在编译出表格错误后,出现了臭名昭著的“对象实例未设置为引用”错误。

Now, for a bit more info... If I comment out the Form_Load events in each of the DetailView concrete/derived classes this error goes away and the form can be viewed in design mode. 现在,更多信息...如果我注释掉每个DetailView具体/派生类中的Form_Load事件,此错误将消失,可以在设计模式下查看该表单。 The Form_Load events have ado.net calls to a sql server which seem to trigger the errors. Form_Load事件具有对sql服务器的ado.net调用,这似乎触发了错误。

With the Form_Load events in tact I don't receive any errors upon compilation and I can run the applications without a problem while in debug or release mode. 有了Form_Load事件,编译时我不会收到任何错误,并且在调试或发布模式下,我可以毫无问题地运行应用程序。 I just can't view any forms with the UserControls in DesignMode. 我只是无法在DesignMode中使用UserControls查看任何形式。

I have added the If Me.DesignMode Then Return to the Form_Load events but it didn't work. 我已经添加了If Me.DesignMode然后返回到Form_Load事件,但是它不起作用。 I think VS2008 is actually trying to run the code in the UserControls... I googled this but I have not found a solution. 我认为VS2008实际上正在尝试在UserControls中运行代码...我用google搜索了这个,但没有找到解决方案。 Any help is MUCH appreciated! 任何帮助深表感谢!

Put a null check in around properties/fields in the Form_Load method. 在Form_Load方法的属性/字段周围进行空检查。 We had similar issues as the designer seems to use FormLoad at design time, not what you would expect. 我们遇到了类似的问题,因为设计人员似乎在设计时使用FormLoad,而不是您期望的那样。

There is also a DesignMode property that you could use. 您还可以使用DesignMode属性。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM