如何在 Bunifu UI 的文本框中切换或编码占位符/水印 属性
How to toggle or code the Placeholder / Watermark Property on a textbox in Bunifu UI
我无法找到使用 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()
代码)
我无法找到使用 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()
代码)