如何继承派生形式的基本形式 [英] how to inherit the base form in derived form

查看:77
本文介绍了如何继承派生形式的基本形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb.net制作桌面应用程序.

我有3种形式,一种是基本形式,两种是衍生形式.

我已使用此代码:

I am making a desktop application using vb.net.

I have 3 forms one base form and two derived forms.

I have used this code:

Public Class frmmain
    Inherits inheritance1.frmbase



这里的继承是项目名称,frmmain是派生形式,frmbase是基本形式.

我收到一个错误:
错误1为类"frmmain"指定的基类"frmbase"不能与其其他部分类型之一的基类"System.Windows.Forms.Form"不同.



Here inheritance is project name and frmmain is derived form and frmbase is base form.

I am getting an error:
Error 1 Base class ''frmbase'' specified for class ''frmmain'' cannot be different from the base class ''System.Windows.Forms.Form'' of one of its other partial types.

推荐答案

尝试此操作...

首先创建基本表单,然后添加新项并选择继承的表单,然后选择基本表单.
这通过您获得了继承的基本形式....

也尝试这个链接...

http://www.codeproject.com/KB/dotnet/BestFormInheritance.aspx
Try to this...

First Create Base form and then go to add new item and select Inherited form and then select Base form.
This through you get inherited base form....

also try this link...

http://www.codeproject.com/KB/dotnet/BestFormInheritance.aspx


嗯,这似乎是VS错误(或功能?).您应该在inheritance.frmbase行下面有一条弯曲的蓝色线条.这应该使您可以选择将声明更改为完全相同的内容inheritance.frmbase.只需选择该选项,错误即可自行解决.

希望这对您有帮助.
Ah, this just seems to be a VS bug (or feature ?). You should have a blue squiggly line underneath the inheritance.frmbase line. This should give you the option of changing the declaration to exactly the same thing inheritance.frmbase. Just select that and the error should resolve itself.

Hope this helps


对于WinForms中的VB,您实际上有两个部分类:一个包含您的代码,一个包含自动生成的设计器代码.当您转到表单代码时,您会看到您的代码的编写位置.在该页面上,转到右上角的下拉菜单,并注意显示为灰色的两个方法Dispose(boolean)InitializeComponent.选择其中一个,然后转到VS代码自动生成的 other 代码模块,以管理表单.

这些模块的两者必须都继承自同一类.否则,编译器将无法将模块合并到单个表单类中,并且您会收到错误消息.因此,在代码模块中设置了Inherits之后,转到设计器模块并将Inherits System.Windows.Forms.Form更改为Inherits frmmain.和谐将得以恢复.
With VB in WinForms, you actually have two partial classes: one with your code, and one with the automatically generated designer code. When you go to the code of a form, you see where your code is written. From that page, go to the drop-down in the upper right and note the two methods that are grayed out, Dispose(boolean) and InitializeComponent. Select either of those, and you are taken to the other code module, with the code that VS generates automatically to manage the form.

Both of these modules must inherit from the same class. When they do not, the compiler cannot merge the modules into the single form class, and you get your error. So after setting the Inherits in your code module, go to the designer module and change Inherits System.Windows.Forms.Form to Inherits frmmain. Harmony will be restored.


这篇关于如何继承派生形式的基本形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆