如何给textBox赋予初始值?
我希望我的 C# 程序的文本框
具有初始值。例如,在其中一个文本框
中,应显示“请输入您的姓名”
。
当您单击(或 tabStop)文本框
时,初始值应该消失,用户将能够在文本框
中输入内容。
我可以使用 click_event
完成所有这些操作,但使用此方法初始文本的不透明度不会降低。我怎样才能实现这一目标?
I want my C# program to have initial values for its textboxes
. For example, in one of the textboxes
, it should say "Please enter your name"
.
When you click (or tabStop) on the textbox
, the initial value should disappear and the user will be able to enter their input to the textbox
.
I can do all this with click_event
, but using this method the initial text would not have less opacity. How am I able to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是我最终做到的:
This is how I finally did it:
我假设您正在谈论 winform (tabstop),您必须在事件按键中处理它。您可以使用下面的代码:
这将选择文本,一旦用户开始输入,窗口就会为您删除它
您可以使用相同的代码为 TabStop 提供此行为
I assume you are talking about winform (tabstop) you have to handle it within the event key-press. you can use the below code:
this will select the text and window will remove it for you as soon as the user start to typing
you can use the same code to have this behavior also for TabStop
您需要做的就是设置文本框的 .Text 属性,并在用户单击(或按 Tab 键)开始输入时使用 GotFocus 事件来清除该框。
请始终记住,除了鼠标之外,还有更多方法可以导航窗体,因此请使用 GotFocus 事件来确定用户何时进入控件,并使用 Validated 事件来确定用户何时更改数据并退出控件。
All you need to do is set the Textbox's .Text property and use GotFocus event to clear the box when the person clicks (or tabs) into it to start typing.
Always remember that there are more ways than the mouse to navigate a form, so use the GotFocus event to determine when the user enters a control, and use the Validated event to determine when they've changed data and exited the control.
对于这种类型的效果,您需要 java 脚本。因为 java 脚本为您提供了鼠标悬停和鼠标移出的功能,这些功能为您提供了与您在本搜索栏页面中看到的相同功能。如果您需要代码回复我我可以给您。
For this type of effect you need java script.Because java script provide you functionality of mouse hover and mouse out these are the functions which provide you the same functionality which u seeing in this page of search bar. If you need code reply me i can give you.