什么是事件处理程序以及如何添加它? [英] what is event handler and how to add it?

查看:81
本文介绍了什么是事件处理程序以及如何添加它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是事件处理程序?

我需要知道这段代码的含义:

What is an event handler?

I need to know the meaning of this code:

Dim entryValue As TextBox = CType(e.Control, TextBox)
AddHandler entryValue.KeyPress

推荐答案

事件处理程序负责事件发生时与调用相关的方法
假设我们想在文本框中按下键时要做一些事情
因此,为按键事件添加处理程序
event handler is responsible for call related method when event occur
suppose we want to do something when key-pressed in textbox
so,add handler for keypress event
dim txt as new Textbox
AddHandler txt.KeyPress, AddressOf txt_KeyPress


Private Sub txt_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 
...
End sub




阅读这篇文章将对您有帮助
http://blackwasp.co.uk/CSharpEventAccessors.aspx [




read this article will help you
http://blackwasp.co.uk/CSharpEventAccessors.aspx[^]

Happy coding!
:)


事件处理程序是处理事件的例程.

最容易理解的事件是按钮按下事件,如果将按钮插入对话框,那么您将要对按下该按钮的事件做出反应.

事件处理程序(通常从对话框编辑器或类向导添加)将处理该事件,并使用其参数允许程序员过滤和处理该事件中需要处理的内容.

用伪代码:
An event handler is a routine that handles an event.

The easiest event to understand is the button press event, if you insert a button into a dialog, then you will want to react to the event of pressing that button.

The event handler (typically added from the dialog editor or the class wizard) will take care of that event and using it''s parameters allow the programmer to filter and process what is needed to be handled in that event.

in pseudocode:
OnBtnClick()
{
  MessageBox("you have pressed the button");
}



看看此
维基百科文章 [



Take a look at this wikipedia article[^] which explains it very well (from the event itself to the event handler).

Good luck!


请参阅以下文章

逐步:在C#中进行事件处理 [ ^ ]

C#中的事件和事件处理 [
See below articles

Step by Step: Event handling in C#[^]

Events and event handling in C#[^]


这篇关于什么是事件处理程序以及如何添加它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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