过去几天我一直在使用winforms玩MVP模式,只有一件事我不知道该怎么做。你如何从另一个视图创建子窗体。这是否是一个有效的选择。加载MVP的子视图
public class MyForm : IMainFormView
{
private MainFormPresenter pres;
public MyForm() { pres = new MainFormPresenter(this); }
//Event from interface.
public event EventHandler<EventArgs> LoadSecondForm;
public void SomeButtonClick()
{
LoadSecondForm(this, EventArgs.Empty);
}
}
public class MainFormPresenter
{
private IMainFormView mView;
public MainFormPresenter(IMainFormView view) {
this.mView = view;
this.Initialize();
}
private void Initialize() {
this.mView.LoadSecondForm += new EventHandler<EventArgs>(mView_LoadSecondForm);
}
private void mView_LoadSecondForm(object sender, EventArgs e) {
SecondForm newform = new SecondForm(); //Second form has its own Presenter.
newform.Load(); // Load the form and raise the events on its presenter.
}
}
我主要关心的是你将如何加载使用这种模式子窗体,你会怎么说,通过从第一页到子窗体的ID。
谢谢。