选中时清除文本框 [英] Clear Textbox when its selected

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

问题描述

您好,

我是visual studio的新用户,我想通过键盘上的Tab键选中文本框中的文本。是否有可能这样做或者是通过点击它来清除文本框的唯一选项。

I am a new user of visual studio and i wanted to make my text in the textbox clear when it is selected with the Tab button on your keyboard. Is there a possible way of doing this or is the only option to clear the textbox by clicking on it with.

这就是我现在拥有的:

private void textBox1_Click(object sender,EventArgs e)

        {

            if(textBox1.Text ==" Username")

            {

                textBox1.Clear();

            }

private void textBox1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "Username")
            {
                textBox1.Clear();
            }

但我希望它在选中时清除文本框时会清除。

but i want it that it clears when the textbox is cleared when its selected.

推荐答案

似乎你想要"水印"。而不是单击,考虑
输入事件(将删除水印)和离开事件(如果文本框将恢复水印)是空的)。请参阅方法:

https: //social.msdn.microsoft.com/Forums/windows/en-us/10f75954-6d14-4926-a02d-98649653b9c8

Seems that you want "watermarks". Instead of Click, consider Enter event (that will remove watermark) and Leave event (that will restore the watermark if the textbox is empty). See an approach: https://social.msdn.microsoft.com/Forums/windows/en-us/10f75954-6d14-4926-a02d-98649653b9c8.

但您仍然可以使用熟悉的标签而不是水印。


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

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