VBA提示文本中的文本文本框中的文本

发布于 2025-02-12 11:43:06 字数 82 浏览 1 评论 0原文

如何在userform中将提示文本添加到textbox中,该一旦用户键入任何内容就会消失?

How to add a hint text to a TextBox in a UserForm that will disappear once a user types anything in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面犯桃花 2025-02-19 11:43:06
  1. 添加标签元素。
  • 键入提示文本。
  • SET BackColor高度topwidth属性匹配该属性textbox将在以后添加。

注意:设置backcolor 窗口背景(从下拉列表中)将与文本框的常见背景颜色匹配。

  • SET forecolor属性(与textbox文本颜色不同,可以将提示文本与输入的文本区分开)。
  1. 添加Textbox元素。
  • SET BackColor高度,<代码>左,topwidth属性。
  • SET Backstyle属性属于fmbackStyletRansparent
  1. 将以下代码添加到sub textbox_change
   If TextBox.Value = "" Then
     TextBox.BackStyle = fmBackStyleTransparent
   Else
     TextBox.BackStyle = fmBackStyleOpaque
   End If

这是结果:

“结果”

  1. Add a Label element.
  • Type a hint text.
  • Set BackColor, Height, Left, Top, and Width properties to match that of the TextBox that will be added later.

Note: Setting BackColor to Window Background (from the drop-down list) will match the common background color of a text box.

  • Set ForeColor property (a different from TextBox text color allows to distinguish the hint text from the entered one).
  1. Add a TextBox element.
  • Set BackColor, Height, Left, Top, and Width properties.
  • Set BackStyle property to fmBackStyleTransparent.
  1. Add the following code to Sub TextBox_Change:
   If TextBox.Value = "" Then
     TextBox.BackStyle = fmBackStyleTransparent
   Else
     TextBox.BackStyle = fmBackStyleOpaque
   End If

Here is the result:

The result

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文