C# 内部委托方式 外部类实现方法

2017-11-21  本文已影响0人  a9b854aded01

想在页面逻辑中定义方法 ,在页面中实现方法 因为需要调用页面控件 。
定义一个C#的内部委托方式 内部定义方法 外部实现这个方法。

在内部定义一个委托方法
``
public delegate void BtnSaveHandler();
public BtnSaveHandler Save;

>在需要的地方执行这个委托方法

if(Save != null)
{
Save();
}



>在外部类中实现这个Save()方法

fsmp.Save += ( ) =>
{
this.tabControl1.Enabled = true;
};




第二个例子 传值


public delegate void BtnSaveHandler(OutPlanView outPlanView);
public BtnSaveHandler Save;
 if (Save != null)
                {
                    Save(SceBind[rowindex]);
                }
 frmDeliveryConfirmationDetailPresenter frm = new frmDeliveryConfirmationDetailPresenter(new frmDeliveryConfirmationDetail(), _dep_ID, bce, se,_protocol,_address);
            frm.Save += (OutPlanView outPlanView) =>
            {
                zentity = outPlanView;
                SetDgvSource(zentity);
            };
            frm.View.ShowDialog();

注意: 委托方法要放在ShowDialog()方法前面 否则ShowDialog会阻塞代理方法的执行。

上一篇 下一篇

猜你喜欢

热点阅读