文本框文本在文本输入 Excel VBA 上消失
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21536192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Textbox Text Disappear on Text Entry Excel VBA
提问by CaptainABC
Basically I have a Userform that I have created, and I was wondering if it was possible to add Grey text that is there when the Userform loads but that disappears as soon as the user start to input text into the TextBox:
基本上我有一个我创建的用户表单,我想知道是否可以添加用户表单加载时存在的灰色文本,但一旦用户开始将文本输入到文本框中,它就会消失:
Userform http://im34.gulfup.com/rDwF8.png
用户表单 http://im34.gulfup.com/rDwF8.png
Once the user starts typing in the font color should change to black.
一旦用户开始输入字体颜色应该变为黑色。
Any help would be appreciated.
任何帮助,将不胜感激。
回答by Siddharth Rout
Something Like this?
像这样的东西?
Private Sub UserForm_Initialize()
TextBox1.ForeColor = &HC0C0C0 '<~~ Grey Color
TextBox1.Text = "Please Enter Name Here"
CommandButton1.SetFocus '<~~ This is required so that the focus moves from TB
End Sub
Private Sub TextBox1_Enter()
With TextBox1
If .Text = "Please Enter Name Here" Then
.ForeColor = &H80000008 '<~~ Black Color
.Text = ""
End If
End With
End Sub
Private Sub TextBox1_AfterUpdate()
With TextBox1
If .Text = "" Then
.ForeColor = &HC0C0C0
.Text = "Please Enter Name Here"
End If
End With
End Sub
ScreenShot (In action)
屏幕截图(在行动)