我们如何在C#中使用户控件的按键事件 [英] how can we make a keypress event of a user control in c#

查看:84
本文介绍了我们如何在C#中使用户控件的按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,该用户控件中有一个文本框,因此我想通过键盘上的Evert键连续访问用户控件文本框中的变量中的每个字母.

如果您将通过代码指导我,那么对我会更好.

I have a usercontrol,in the usercontrol there is a textbox,so i want to access the every letter continiously in a variable from the textbox of usercontrol on evert key pressing from keyboard.

If u will guide me through code,so it will be better for me.

推荐答案

1.您的UserControl需要一个自定义事件:TextBoxTextChanged,其签名类似于标准的 EventHandler [ ^ ].每当 TextBox [ TextChanged [
1. Your UserControl needs a custom event: TextBoxTextChanged with its signature like a standard EventHandler[^]. Fire the event whenever the TextBox[^] fires its TextChanged[^] event.
2. Your UserControl needs a public property TextBoxText, too. Implement only the getter part returning the TextBox''s current text.

3. The second UserControl needs to subscribe to the first UserControl''s TextBoxTextChanged event. Upon firing of the event, an event handler routine will be called. In the event handler, copy text from sender''s TextBoxText property (if existing) to this.TextBox1.Text (or whatever it is actually called).


这篇关于我们如何在C#中使用户控件的按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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