文本框文本在Excel VBA上消失

问题描述 投票:3回答:2

基本上,我已经创建了一个用户窗体,我想知道是否可以添加在加载用户窗体时存在的灰色文本,但是一旦用户开始向TextBox中输入文本,该文本就会消失:

Userform http://im34.gulfup.com/rDwF8.png

一旦用户开始输入字体颜色,应更改为黑色。

任何帮助将不胜感激。

excel vba excel-vba
2个回答
10
投票
这样的东西?

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(正在执行)

“在此处输入图像描述”

0
投票
先生, 是否有可能编码,只要在TextBox内单击就不会消失,除非我们在其中输入类似Youtube.com的内容。 如果我们在youtube的搜索框中单击,则在我们键入内容之前,模糊/消失的文本“搜索”不会消失。
© www.soinside.com 2019 - 2024. All rights reserved.