在我的应用程序中,我有一个用于输入用户名的文本框.如果文本为空,我想在灰色的同一文本框中显示"在此处输入用户名".文本框中是否有这样的属性.就像在Firefox浏览器中一样,如果URL字段为空,它将以灰色显示"转到网站"
谢谢
我知道这可能是一个旧线程,但我想我会回答它以防万一其他人偶然发现它.
首先声明以下内容(您可能需要导入System.Runtime.InteropServices)
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
End Function
Run Code Online (Sandbox Code Playgroud)
然后调用以下内容(根据需要进行更改):
SendMessage(Me.textbox1.Handle, &H1501, 0, "Enter User name here")
Run Code Online (Sandbox Code Playgroud)
Jar*_* Ng -1
尝试一些类似的事情:
(onkeyup)
If TextBox.Text = "" Then
TextBox.Text = "Enter username here..."
TextBox.ForeColor = <your chosen color here>
Else
TextBox.ForeColor = <normal color here>
End If
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22857 次 |
| 最近记录: |