我无法以某种方式找到使用 Bunifu UI 在文本框上放置水印或占位符的属性。我需要它用于凭据文本框。我找到了一个源代码,它仅适用于普通文本框,而不适用于 Bunifu 文本框。
这是我的代码:
Imports System.Runtime.InteropServices
Public Class Login
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CenterToParent()
BunifuTextbox2._TextBox.PasswordChar = "*"
SetCueText(BunifuTextbox1, "Username")
SetCueText(BunifuTextbox2, "Password")
End Sub
Private Sub BunifuTextbox1_OnTextChange(sender As Object, e As EventArgs) Handles BunifuTextbox1.OnTextChange
End Sub
End Class
Public Module CueBannerText
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private 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
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Const EM_SETCUEBANNER As Integer = &H1501
Public Sub SetCueText(cntrl As Control, text As String)
If TypeOf cntrl Is Bunifu.Framework.UI.BunifuDropdown Then
Dim Edit_hWnd As IntPtr = FindWindowEx(cntrl.Handle, IntPtr.Zero, "Edit", Nothing)
If Not Edit_hWnd = IntPtr.Zero Then
SendMessage(Edit_hWnd, EM_SETCUEBANNER, 0, text)
End If
ElseIf TypeOf cntrl Is Bunifu.Framework.UI.BunifuTextbox Then
SendMessage(cntrl.Handle, EM_SETCUEBANNER, 0, text)
End If
End Sub
End Module
这是我找到的原始源代码:
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SetCueText(TextBox1, "Enter Name here")
End Sub
End Class
Public Module CueBannerText
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private 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
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Const EM_SETCUEBANNER As Integer = &H1501
Public Sub SetCueText(cntrl As Control, text As String)
If TypeOf cntrl Is ComboBox Then
Dim Edit_hWnd As IntPtr = FindWindowEx(cntrl.Handle, IntPtr.Zero, "Edit", Nothing)
If Not Edit_hWnd = IntPtr.Zero Then
SendMessage(Edit_hWnd, EM_SETCUEBANNER, 0, text)
End If
ElseIf TypeOf cntrl Is TextBox Then
SendMessage(cntrl.Handle, EM_SETCUEBANNER, 0, text)
End If
End Sub
End Module
如前所述,BunifuTextBox
包含一个常规的WinForms文本框。您找到的代码是为这样的文本框设计的,因此您需要做的就是为BunifuTextBox
的基础文本框设置提示横幅:
SetCueText(BunifuTextbox1._TextBox, "Username")
(这使用您找到的原始SetCueText()
代码(