表格继承。无法转换类型

时间:2015-08-27 22:38:03

标签: c# winforms inheritance

我有一个类613566757 / 4294967296 for outcomes 0,1,2,3 613566756 / 4294967296 for outcomes 4,5,6 ,它应该使用EmployeeAccountPresenter(继承自EmployeeAccountView类)和Form类的对象进行操作。

EmployeeBridge

namespace DBEmployee { class EmployeeAccountPresenter { public EmployeeAccountView form; public EmployeeBridge bridge; public EmployeeAccountPresenter(EmployeeAccountView _form, EmployeeBridge _bridge) { this.form = _form; this.bridge = _bridge; } } } 上课:

EmployeeAccountView

在我的Form1课程中,我做了:

namespace DBEmployee
{
    class EmployeeAccountView : Form
    {...

但我在这个'中得到了一个错误。参数:

  

无法转换为' DBEmployee.Form1'至   ' DBEmployee.EmployeeAccountView'

namespace DBEmployee { public partial class Form1 : Form { public Form1() { InitializeComponent(); EmployeeBridge eb = new EmployeeBridge(); EmployeeAccountPresenter eap = new EmployeeAccountPresenter(this, eb); } } } 类继承自EmployeeAccountView类。为什么我不能转换?

1 个答案:

答案 0 :(得分:3)

this引用当前对象,类型为Form1Form1又是Form的子类。

EmployeeAccountView无处可去。

我怀疑你确实想要像这样定义你的表单:

public partial class Form1 : EmployeeAccountView

现在this将是EmployeeAccountView的子类型,可以作为参数传递给EmployeeAccountPresenter