文本输入时消失文本框文本 [英] Textbox Text Disappear on Text Entry

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

问题描述

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

[图片已过期]

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

任何帮助将不胜感激.

解决方案

像这样的东西吗?

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(实际)

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:

[image expired]

Once the user starts typing in the font color should change to black.

Any help would be appreciated.

解决方案

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)

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

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