Introduction
This a VB.NET reworking of C# Cue Banner by Ravi Bhavnani.
The code has minor changes to allow the setting of cue banners for combo boxes as well as text boxes and an alternative extension method style of use is shown.
If you're thinking about developing for a touch interface you'll need cue banners as tooltips aren't going to be an option.
Using the code
Class Based
Watermark.Set(Textbox1, "My cue banner")
Watermark.Set(Combobox1, "Yet another cue banner")
Extension Method Based
Textbox1.CueBannerSet("My cue banner")
Combobox1.CueBannerSet("Yet another cue banner")
The Code
There is so little code that it can be shown here in its entirety.
Watermark Class
#Region "Imports"
mports System.Runtime.InteropServices
#End Region
Public Class Watermark
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal Msg As UInteger, _
ByVal wParam As IntPtr, _
ByVal lParam As String) As IntPtr
End Function
Public Shared Sub [Set](ByVal ctl As Control, byval hintText as string)
Const EM_SETCUEBANNER as Int32 = &h1501
Const CB_SETCUEBANNER As Int32 = &h1703
Dim retainOnFocus As IntPtr = new IntPtr(1)
Dim msg As Int32 = EM_SETCUEBANNER
If TypeOf ctl is ComboBox
msg = CB_SETCUEBANNER
End If
SendMessage(New HandleRef(ctl, ctl.Handle), _
msg, _
retainOnFocus, _
hintText)
End sub
End Class
Extension Method Module
#Region "Imports"
mports System.Runtime.CompilerServices
#End Region
Module ControlExtensions
<Extension()> _
Public Sub CueBannerSet(ctl as Control, hintText As String)
Watermark.Set(ctl, hintText)
End Sub
End Module
Points of Interest
Cue banners are not displayed for multiline textboxes.
You may find that you have to call Application.EnableVisualStyles
before Application.Run
for cue banners to be displayed.
Application.EnableVisualStyles
Application.Run(new Form1)
History
- December 2012. First cut.