由网友(Cherish.(珍惜))分享简介:我知道,在C#中,有几个建在传递一个参数(取消)事件,如果将它设置为真将停止进一步执行中引发该事件的对象。I know that in C#, there are several built in events that pass a parameter ("Cancel") which if set to true...
我知道,在C#中,有几个建在传递一个参数(取消)事件,如果将它设置为真将停止进一步执行中引发该事件的对象。
I know that in C#, there are several built in events that pass a parameter ("Cancel") which if set to true will stop further execution in the object that raised the event.
你将如何实现一个事件在其募集对象是能够跟踪的属性在EventArgs的?
How would you implement an event where the raising object was able to keep track of a property in the EventArgs?
下面是什么,我试图做一个WinForms例如: http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx
Here is a WinForms example of what I am trying to do: http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx
感谢你。
推荐答案
这真的很容易。
private event _myEvent;
// ...
// Create the event args
CancelEventArgs args = new CancelEventArgs();
// Fire the event
_myEvent.DynamicInvoke(new object[] { this, args });
// Check the result when the event handler returns
if (args.Cancel)
{
// ...
}
相关推荐
最新文章