system.windows.forms.form的继承问题

发布于 2025-01-21 06:34:08 字数 1398 浏览 0 评论 0原文

我正在研究其他人的较旧的UI自定义项目(VB.NET Windows表单),并且似乎遇到了与继承有关的某种问题。我可以像我所说的那样轻松地复制问题,但是为什么我要让我正在研究的项目以完全相同但似乎并没有受到影响的影响。

示例代码

假设我们要创建自己的表单类,它将具有特殊的属性,事件处理程序等

Public Class MyFormBase
    Inherits System.Windows.Forms.Form
End Class

。 :

Inherits MyNamespace.MyFormBase

从而替换form1.designer.vb中的继承

继承system.windows.forms.form

错误消息

当我尝试查看Form1的设计视图时,它会被此错误阻止:

无法显示该文件的设计师,因为其中没有一个类。设计人员检查了文件中的以下类:Form1 ---无法加载基类“ myformbase”。确保已引用大会并建立了所有项目。

但是,它在这里起作用...

当我查看我正在研究的VB.NET项目的代码时,它的编码完全相同,但是它的工作/运行根本没有任何问题。他们都从rjmainform继承:

form.designer.vb:

Partial Class MainFormDemo
    Inherits RJCodeUI_M1.RJMainForm

and form.vb:

Public Class MainFormDemo
    Inherits RJMainForm

他说他最初在VS2012中创建了自己的项目。我尝试使框架版本匹配(从而引用完全相同的库文件),添加了完全相同的引用等。

结论

为什么这在他的解决方案中起作用而不是我的?我曾经经历过每个配置文件和其他所有内容,但是找不到任何解释。

更新#1

我正在从中学到的较旧项目包括实际的.vb类文件,因此我在执行继承时会引用其中的类。

作为测试,我做了Jimi建议并创建了一种继承的形式。但是您必须参考我没有的DLL-我有几个.vb类文件分布在多个目录上。它花了一些时间,但是我设法将所有这些都变成了DLL,并将其用作继承形式的基础。这种继承的形式方法无问题,这是一个很棒的长期解决方案,因为我现在可以重复使用DLL。

不幸的是,这使我无法更接近理解我原始方法的实际问题,因此我仍然希望有人能够解释我原始的示例代码有什么问题。

I'm studying an older UI customization project (VB.NET Windows forms) by someone else and seem to be running into some kind of problem relating to inheritance. I can duplicate the issue easily, as I'll show, but why I'm baffled is that the project I'm studying is coded the exact same way but doesn't seem affected by this.

Example Code

Let's say we want to create our own form class like so, which would have special properties, event handlers etc.:

Public Class MyFormBase
    Inherits System.Windows.Forms.Form
End Class

And then in both our Form1.vb and Form1.designer.vb, we add:

Inherits MyNamespace.MyFormBase

thus replacing the inheritance in Form1.designer.vb which previously said

Inherits System.Windows.Forms.Form

The Error Message

When I try to view the design view of Form1, it is blocked with this error:

The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: Form1 --- The base class 'MyFormBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

But, It Works Here...

When I look at the code for the VB.NET Project I'm studying, it's coded exactly the same way, and yet it works/runs without any problem at all. They both inherit from RJMainForm:

form.designer.vb:

Partial Class MainFormDemo
    Inherits RJCodeUI_M1.RJMainForm

and form.vb:

Public Class MainFormDemo
    Inherits RJMainForm

He said that he created his project originally in VS2012. I tried making the Framework versions match (thus referencing the exact same library files), adding the exact same references etc.

Conclusion

Why does this work in his solution but not mine? I've been through every config file and everything else, but can't find any explanation.

UPDATE #1

The older project that I was learning from included the actual .vb class files, so I was referencing the classes in them when doing my inheritance.

As a test, I did what Jimi suggested and created an Inherited Form. But you have to reference a DLL, which I didn't have - I had several dozen .vb class files spread out over multiple directories. It took some doing, but I managed to turn all of that into a DLL and use it as the basis of an Inherited Form. This Inherited Form approach works without issue and is a great long term solution, since I can now re-use the DLL.

Unfortunately, this brings me no closer to understanding what the actual problem is in my original approach, so I'm still hoping someone will be able to explain what's wrong with my original example code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文