C# 形式继承。无法转换类型
我有一个类C# 形式继承。无法转换类型,c#,winforms,inheritance,C#,Winforms,Inheritance,我有一个类EmployeeAccountPresenter,它应该与EmployeeAccountView(从表单继承而来)和EmployeeBridge类的对象一起操作 namespace DBEmployee { class EmployeeAccountPresenter { public EmployeeAccountView form; public EmployeeBridge bridge; public Emplo
EmployeeAccountPresenter
,它应该与EmployeeAccountView
(从表单继承而来)和EmployeeBridge
类的对象一起操作
namespace DBEmployee
{
class EmployeeAccountPresenter
{
public EmployeeAccountView form;
public EmployeeBridge bridge;
public EmployeeAccountPresenter(EmployeeAccountView _form, EmployeeBridge _bridge)
{
this.form = _form;
this.bridge = _bridge;
}
}
}
EmployeeAccountView
class:
namespace DBEmployee
{
class EmployeeAccountView : Form
{...
在我的Form1课程中,我做:
namespace DBEmployee
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
EmployeeBridge eb = new EmployeeBridge();
EmployeeAccountPresenter eap = new EmployeeAccountPresenter(this, eb);
}
}
}
但是我在'this'参数中得到一个错误:
无法从“DBEmployee.Form1”转换为
“DBEmployee.EmployeeAccountView”
EmployeeAccountView
类继承自表单
类。为什么我不能皈依 此
引用当前对象,其类型为Form1
Form1
又是Form
的子类
EmployeeAccountView
没有任何地方发挥作用
我怀疑你真的想这样定义你的表单:
public partial class Form1 : EmployeeAccountView
现在,此
将是EmployeeAccountView
的一个子类型,可以作为参数传递给EmployeeAccountPresenter