在过去的几天里,我一直在使用 winforms 玩 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 从第一页传递给子表单。
谢谢。