如何发送KeyEventArgs作为方法参数 [英] How Do i Send KeyEventArgs As Method Parameters

查看:685
本文介绍了如何发送KeyEventArgs作为方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我为控制键编写了此方法.

如何将参数发送给该方法?

****************************************************** ************

Hello everyone,

I wrote this method for control keys .

How to be sent to parameter this method?

**************************************************************

Public void KeyContoroler(KeyEventArgs e)
{
if(e.keychar==keys.Enter)
{
    messagebox.show("Enter Pressed");
}

if (e.keychar==keys.escape)
{
    messagebox.show("Escape Pressed");
}
}



****************************************************** ************

对我来说很重要.

请帮帮我.



**************************************************************

It''s very important for me.

Please help me.

推荐答案

仅编写方法将无济于事,您必须将其挂接到事件上,并将其作为可接受的事件处理程序提供-这意味着两个参数,对象发送者"和"KeyEventArgs e"-不是一个.

两种方法.
1)在表单设计器中,突出显示要处理偶数的控件,然后在属性"窗口中选择事件"-它是带有闪电的小按钮.双击KeyPress事件,将生成一个处理程序,并提供一个最小方法.
2)在代码查看器中,可能在FormLoad事件中,通过键入控件名称,然后键入".KeyPress",然后再键入"+ ="和两次Tab键,来添加处理程序.这将创建与上述相同的方法并将其挂接到事件中.
Just writing a method will do nothing, you have to hook it to the event, and supply it as an acceptable eventhandler - which mean two parameters, "object sender" and "KeyEventArgs e" - not one.

Two ways to do it.
1) In the form designer, highlight the control you want to handle the even, and select Events on the Properties window - it''s the little button with a lightning bolt on it. Double click the KeyPress event and a handler will be generated and a minimal method supplied.
2) In the code viewer, probably in the FormLoad event, add a handler by typing your control name followed by ".KeyPress", then "+=" followed by the Tab key twice. This will create the same method as above and hook it into the event.


这篇关于如何发送KeyEventArgs作为方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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