也不知是哪位狐友发布的,搬来用,效果还行:
此主题相关图片如下:微信截图_20230419100150.png
'全局代码定义文本控件提示信息显示
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As Byte()) As Integer
Public Const EM_SETCUEBANNER As Integer = &H1501
Public Sub SetWatermark(wTextBox As winform.textbox, str As String)
SendMessage(wTextBox.BaseControl.Handle, EM_SETCUEBANNER, IntPtr.Zero, System.Text.Encoding.Unicode.GetBytes(str))
End Sub
Public Sub SetWatermark(wComboBox As winform.ComboBox, str As String)
SendMessage(wComboBox.BaseControl.Handle, EM_SETCUEBANNER, IntPtr.Zero, System.Text.Encoding.Unicode.GetBytes(str))
End Sub
’窗口Afterload设置
SetWatermark(e.Form.Controls("DBname"), "请选择账套")
SetWatermark(e.Form.Controls("UserName"), "请选择用户")
SetWatermark(e.Form.Controls("PassWord"), "请输入密码")
使用过程发现一个问题,打开窗口后如果焦点在文本框,那么这个文本框默认提示信息失效,可以设置打开窗口将焦点设为其他控件;如果窗口只有以上3个文本框,变通方法为加入一个标签控件(文本为空),并设置打开窗口将焦点设为此控件。
e.Form.controls("Label1").Select
完美解决!
[此贴子已经被作者于2023/4/19 10:21:21编辑过]