C# 自动清除 Winform 文本框 [英] C# Auto Clearing Winform Textbox

查看:31
本文介绍了C# 自动清除 Winform 文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户希望能够选择一个文本框并选择当前文本,这样他就不必为了更改内容而将其全部突出显示.

I have a user that want to be able to select a textbox and have the current text selected so that he doesn't have to highlight it all in order to change the contents.

按下回车时需要处理内容.那部分我想我已经想通了,但欢迎提出任何建议.

The contents need to be handle when enter is pushed. That part I think I have figured out but any suggestions would be welcome.

我需要帮助的部分是,一旦按下 Enter,文本框中的任何条目都应再次清除内容.

The part I need help with is that once enter has been pushed, any entry into the textbox should clear the contents again.

文本框控制一块 RF 硬件.用户希望能够做的是输入设置并按回车键.设置被发送到硬件.无需做任何其他操作,用户就希望能够输入新设置并再次按 Enter.

The textbox controls an piece of RF hardware. What the user wants to be able to do is enter a setting and press enter. The setting is sent to the hardware. Without doing anything else the user wants to be able to type in a new setting and press enter again.

推荐答案

钩入 TextBox 上的 KeyPress 事件,当它遇到 Enter 键时,运行你的硬件设置代码,然后再次高亮文本框的全文(见下文)- Windows 将负责为您清除下一次击键时的文本.

Hook into the KeyPress event on the TextBox, and when it encounters the Enter key, run your hardware setting code, and then highlight the full text of the textbox again (see below) - Windows will take care of clearing the text with the next keystroke for you.

TextBox1.Select(0, TextBox1.Text.Length);

这篇关于C# 自动清除 Winform 文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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