【问题标题】:Return focus to placeholder in text boxMicrosoft Access - 文本框 VBA 中的占位符
【发布时间】:2021-12-21 12:23:28
【问题描述】:

我有一个登录表单。我有一个带有登录和关闭按钮的用户名和密码文本框。

我想要:

  • 在用户名中显示“用户名”,在密码字段中显示“密码”。
  • 点击时文字消失。
  • 如果点击后您专注于其他内容而不输入任何内容,它将返回占位符。

我试过了:

Private Sub Form_Load()
txt_username.Value = "Username"
txt_password.Value = "Password"
End Sub

Private Sub txt_username_Click()
If txt_username.Value = "Username" Then
txt_username.Value = ""
End If
End Sub

Private Sub txt_username_LostFocus()
If txt_username.Value = "" Then
txt_username.Value = "Username"
End If
End Sub

我唯一的问题是当进行更改时,IE 你输入一些内容,然后删除它,在你做其他事情之后占位符不会返回。打字会破坏我的代码。

请帮忙。 汤姆

【问题讨论】:

    标签: vba database validation ms-access-2016


    【解决方案1】:

    你很亲密。尝试使用“GotFocus”而不是“Click”:

    Option Explicit
    
    Private Sub Form_Load()
       txt_username.Text = "Username"
       txt_password.Text = "Password"
    End Sub
    
    Private Sub txt_username_GotFocus()
       If Trim(txt_username.Text) = "Username" Then
          txt_username.Text = ""
       End If
    End Sub
    
    Private Sub txt_username_LostFocus()
       If Trim(txt_username.Text) = "" Then
          txt_username.Text = "Username"
       End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 2015-12-15
      • 2011-07-29
      • 2023-04-08
      • 2015-12-15
      • 2014-02-14
      相关资源
      最近更新 更多