Add this Module (ModExtentions
) to the Project: it adds an extension method, SetCueBanner()
, to TextBox Controls.
Specifying True
or False
, changes the cue banner behavior:
- False: the cue banner is visible until the control gets focus,
- True, the cue banner is visible until the first char is entered.
This internal functionality is activated sending an EM_SETCUEBANNER
message to the Control.
Use it like this:
' The Cue Banner is visible until the control gets focus
TextBox1.SetCueBanner("Some text...", False)
' The Cue Banner is visible until a character is entered
TextBox1.SetCueBanner("Some text...", True)
The Module where the extension method is defined:
Imports System.Runtime.InteropServices
Public Module ModExtentions
Private Const EM_SETCUEBANNER As Integer = &H1501
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Private Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
End Function
<Extension()>
Public Sub SetCueBanner(tbox As TextBox, ByVal text As String, ByVal showOnFocus As Boolean)
SendMessage(tbox.Handle, EM_SETCUEBANNER, If(showOnFocus, 1, 0), text)
End Sub
End Module