vba - 仅在第一次时在 MouseDown/MouseUp 上清空预填充的 TextBox
问题描述
我是 word-vba 的新手(只是为了让你知道我的问题可能真的很愚蠢)。
我只想在第一次单击文本框时清除文本框。
我试过 For... Next 但我无法正确配置它
Private Sub SWName_Field_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
SWName_Field.Text = ""
End Sub
我希望代码的工作方式与它的工作方式完全相同,但是当我输入一些文本时,例如用户犯了错误或拼写错误,文本框中的第二次点击不应该清除里面的文本。
谢谢你的支持
解决方案
任何 UserForm 控件中都没有内置的活动状态标识符。因此,您需要使用元数据来指定和识别您的 mousedown 是否是第一次发生。
为此使用Tag
控件的属性。
有关详细信息,请参阅代码注释。
Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'/ Use the Tag field to determine and store the state of Text Box.
If Len(Me.TextBox1.Tag) < 1 Then
'/ If Mousedown for the very first time then TextBox's tag is empty.
'/ Go ahead, clean the textbox.
'/ And set a text in tag.
Me.TextBox1.Text = ""
Me.TextBox1.Tag = "Text Cleared"
End If
End Sub
推荐阅读
- api - 我不想清除柏树中的现金和饼干
- python - 如何在python中生成独特的彩色图像
- flutter - 按下时浮动操作按钮的奇怪背景形状
- java - 3D对象SceneView Sceneform android的CameraPreview
- wordpress - wordpress 网站 url 上的前缀导致 404 错误
- javascript - 悬而未决的承诺已取消
- pcregrep - Pcregrep Perl 正则表达式积极的后视
- c - 接收缓冲区数据时套接字错误 10054 - winsock2.h 库
- c# - c#不带大括号的记录
- ios - Pod 安装在另一个分支上,而不是主分支