C#Working Visual Studio 2008中的事件处理程序 [英] event handler in c# working visual studio 2008

查看:130
本文介绍了C#Working Visual Studio 2008中的事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自己的组合框,并创建了自己的事件处理程序,我需要知道离开组合时如何使该事件正常工作,例如请假事件


阿萨德
[DELETED] @ hotmail.com

[edit]除非您真的喜欢垃圾邮件,否则请不要在任何论坛中发布您的电子邮件地址!如果有人回复您,您将收到一封电子邮件,通知您-OriginalGriff [/edit]

I create My own combobox and I create my own event handler, i need to know how can i make this event work when i leave the combo such like the leave events


Assaad
[DELETED]@hotmail.com

[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know - OriginalGriff[/edit]

推荐答案

如果您表示自己创建了自己的活动,并且想要知道如何向处理程序发出信号:
If you mean you created your own event, and you want to know how you signal it to handlers then:
/// <summary>
/// Event to indicate My Event happened
/// </summary>
public event EventHandler MyEvent;
/// <summary>
/// Called to signal to subscribers that My Event happened
/// </summary>
/// <param name="e"></param>
protected virtual void OnMyEvent(EventArgs e)
    {
    EventHandler eh = MyEvent;
    if (eh != null)
        {
        eh(this, e);
        }
    }

每当您要发出结束信号并具有连接的处理程序做某事时,只需使用EventArgs实例或null:
调用OnMyEvent方法即可.

Whenever you want to signal the end and have and connected handlers do somethign as a result, just call the OnMyEvent method with either an EventArgs instance, or null:

OnMyEvent(null);



如果您使用的是事件,那么值得考虑一下:添加事件的简单代码段 [ ^ ]-它向Visual Studio添加一个代码段,当您以"prop"生成自动属性的相同方式键入"evh"时,该代码段将为您生成上述代码.

如果那不是您想要的,那是什么?



If you are using events, it might be worth your looking at this: A simple code snippet to add an event[^] - it adds a snippet to Visual Studio which generates the above code for you when you type "evh" in the same way that "prop" generates an automatic property.

If that isn''t what you want, what is?


这篇关于C#Working Visual Studio 2008中的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆