jeudi 12 mars 2015

VB.NET Textbox Cue Banner not setting - no error

(VS2013) So, I've been trying to implement Cue Banners in some of my Text Boxes however, after playing around with code from the internet for around 2 hours with no luck, I came here. Here are the two I've tried without luck.



Imports System.Runtime.InteropServices

Class
Private Const EM_SETCUEBANNER As Integer = &H1501

<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

Private Sub SetCueText(ByVal control As Control, ByVal text As String)
SendMessage(control.Handle, EM_SETCUEBANNER, 0, text)
End Sub
End Class


and



Imports System.Runtime.InteropServices

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


And then this next bit would be used to set the cue text...



SetCueText(ControlName, "Blah")


But neither of these two work. Rather, neither of the two give an error. The text boxes I have tried are Multiline=False.


Aucun commentaire:

Enregistrer un commentaire