CancelEventHandler,CancelEventArgs 怎么在自定义事件里通过e.cancle=true取消事件?

a68351153 2011-10-09 10:19:13

如题:

CancelEventHandler,CancelEventArgs :怎么在自定义事件里通过e.cancle=true取消事件?

操作过程类似Form的FormClosing事件里编写e.cancel=true来取消窗体的关闭一样。

目前个人只做到如此:

public event CancelEventHandler Change;

protected virtual void OnChange(object sender, CancelEventArgs e)
{
if (Change != null)
{
CancelEventHandler handler = Change;
handler(sender, e);
}

if (e.Cancel) //这种实现是不行的
{
//e.Cancel = true
}
else
{
//e.Cancel = false
}
}

private string message;
public string Message
{
get
{
return message;
}
set
{
if (message != value)
{
message = value;
OnChange(null, new CancelEventArgs());
}
}
}

望指教。
...全文
512 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
辛燕青 2012-12-13
  • 打赏
  • 举报
回复
你定义的事件好像没有用到吗.看你的Message的set中直接调用函数了.哈哈,别笑话我啊,我是新手,比你差远啦

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧