MyForm_Presenter


Creating the Presenter

Add a class called "MyForm_Presenter" to the MyForm folder.
Make the following changes to this class.
Change the constructor

public class MyForm_Presenter : 
   MVP.BS_PassiveView<MyForm_Model,
   MyForm_View>
{
   public bool Property_FormCancelled { get; set; }
   
   //-----------------------------------------------------------------------
   public MyForm_Presenter(MyForm_Model model, MyForm_View view)
   {
          base.Initialize(model, view);
          bool showform = model.Method_Initialize();
   
          this.Property_FormCancelled = false;
   
          if (showform == false)
          {
              this.View.Method_Close();
          }
   }
}

Add the following Helper methods

protected override void Method_WireEvents() 
{
   base.View.Method_RegisterChangeRequestListener(
        this.View.GetType().Name,
        new System.EventHandler<MVP.BS_EventArgs<string>>
           (this.Method_OnEvent));
}
//-----------------------------------------------------------------------
protected override void Method_UnwireEvents()
{
   base.View.Method_UnRegisterChangeRequestListener(
        this.View.GetType().Name,
        new System.EventHandler<MVP.BS_EventArgs<string>>
            (this.Method_OnEvent));
}
//-----------------------------------------------------------------------
private void Method_OnEvent(
   object Sender,
   MVP.BS_EventArgs<string> args)
{
       string match = args.RequestedValue.ToString();
       enEvents_MyForm enumValue =
           (enEvents_MyForm)System.Enum.Parse(typeof(enEvents_MyForm), match);

       switch (enumValue)
       {
           case enEvents_MyForm.OK_Click:
               this.Method_Event_CreateClick(Sender, args);
               break;

           case enEvents_MyForm.Cancel_Click:
               this.Method_Event_CancelClick(Sender, args);
               break;

           default:
               break;
       }
}
//-----------------------------------------------------------------------
public void Method_Event_CancelClick(object sender, System.EventArgs e)
{
       this.View.Method_Close();
       this.Dispose();
}
//-----------------------------------------------------------------------
public void Method_Event_OKClick(object sender, System.EventArgs e)
{
       this.View.Method_Close();
       this.Dispose();
}

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext