形成产业.不能转换类型

本文关键字:转换 类型 不能 | 更新日期: 2023-09-27 18:10:05

我得到了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 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类继承自Form类。为什么我不能转换?

形成产业.不能转换类型

this为当前对象,类型为Form1Form1Form的子类。

EmployeeAccountView在任何地方都不起作用。

我猜你是想这样定义你的表单:

public partial class Form1 : EmployeeAccountView

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