WinForms事件是否可用于TextBox? [英] WinForms event for TextBox focus?

查看:52
本文介绍了WinForms事件是否可用于TextBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 TextBox 添加一个偶数,以使其具有焦点.我知道我可以使用一个简单的 textbox1.Focus 并检查bool值...但是我不想那样做.

I want to add an even to the TextBox for when it has focus. I know I could do this with a simple textbox1.Focus and check the bool value... but I don't want to do it that way.

这是我想做的:

this.tGID.Focus += new System.EventHandler(this.tGID_Focus);

我不确定EventHandler是否是执行此操作的正确方法,但我确实知道这是行不通的.

I'm not sure if EventHandler is the correct way to do this, but I do know that this does not work.

推荐答案

您正在寻找GotFocus事件.还有一个LostFocus事件.

You're looking for the GotFocus event. There is also a LostFocus event.

textBox1.GotFocus += textBox1_GotFocus;

这篇关于WinForms事件是否可用于TextBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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