Click here to Skip to main content
12,823,663 members (64,972 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 4 Dec 2012


, 4 Dec 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
VB.NET version of Ravi Bhavnani's CueProvider.


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

''' <summary>
''' Set cue banner text 
''' </summary>
''' <remarks></remarks>
Public Class Watermark

    ''' <summary>
    ''' Send a string parameter message to a control.
    ''' </summary>
    <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

    ''' <summary>
    ''' Set a watermark (a cue banner in the jargon) for a control.
    ''' </summary>
    ''' <param name="ctl">The control that you want the watermark to appear in.</param>
    ''' <param name="hintText">The cue message.</param>
    ''' <remarks></remarks>
    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, _

    End sub

End Class

Extension Method Module

#Region "Imports"
 mports System.Runtime.CompilerServices
#End Region

Module ControlExtensions

    ''' <summary>
    ''' Provide a control based shortcut.
    ''' </summary>
    ''' <param name="ctl"></param>
    ''' <param name="hintText"></param>
    ''' <remarks></remarks>
    <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.Run(new Form1)


  • December 2012. First cut.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United Kingdom United Kingdom
Nothing interesting to report.

You may also be interested in...

Comments and Discussions

QuestionCueText Styling Pin
TobiasVdb21-Jul-14 23:47
memberTobiasVdb21-Jul-14 23:47 
AnswerRe: CueText Styling Pin
cigwork26-Jul-14 22:26
membercigwork26-Jul-14 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 4 Dec 2012
Article Copyright 2012 by cigwork
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid