Click here to Skip to main content
Click here to Skip to main content
Alternative Article
Go to top

CueProvider

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

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"
Imports 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, _
                    hintText)

    End sub

End Class

Extension Method Module

#Region "Imports"
Imports 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.EnableVisualStyles
Application.Run(new Form1)

History

  • December 2012. First cut.

License

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

Share

About the Author

cigwork

United Kingdom United Kingdom
Nothing interesting to report.

Comments and Discussions

 
QuestionCueText Styling PinmemberTobiasVdb21-Jul-14 22:47 
AnswerRe: CueText Styling Pinpremiumcigwork26-Jul-14 21:26 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 4 Dec 2012
Article Copyright 2012 by cigwork
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid