写了一个自定义控件,其中一个按钮,其点击事件的处理内容需要在外部通过调用自定义控件的方法来设置
例如:
自定义控件:
Button _b;//这里不会写了,只写一下大概意思
public void SetClick(参数?)
{
_b.Click += ……;
}窗口中对象 _c=自定义控件
_c.SetClick(ToCreate())private void ToCreate()
{
//例如打开某个窗口
}
例如:
自定义控件:
Button _b;//这里不会写了,只写一下大概意思
public void SetClick(参数?)
{
_b.Click += ……;
}窗口中对象 _c=自定义控件
_c.SetClick(ToCreate())private void ToCreate()
{
//例如打开某个窗口
}
//这2句可以定义一个事件OnButtonClick
public delegate void ButtonClick(object sender,EventArgs e);
public event ButtonClick OnButtonClick;//这里定义了一个激活事件的私有方法
void ActiveOnButtonClick(object sender,EventArgs e)
{
if (OnButtonClick!= null)
{
OnButtonClick(sender,e);
}
}
#endregion//一个按钮,其点击事件
private void button2_Click(object sender, EventArgs e)
{
ActiveOnButtonClick(sender,e);
}
http://topic.csdn.net/u/20090805/16/41a8b980-02bb-4e6e-86d0-26967480b76f.html