Click here to Skip to main content
15,884,629 members
Articles / Programming Languages / C#
Alternative
Article

CueProvider

Rate me:
Please Sign up or sign in to vote.
3.00/5 (3 votes)
4 Dec 2012CPOL 13.7K   9   2
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

VB
Watermark.Set(Textbox1, "My cue banner")
Watermark.Set(Combobox1, "Yet another cue banner")

Extension Method Based

VB
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

VB
#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, _
                    hintText)

    End sub

End Class

Extension Method Module

VB
#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.

VB
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)


Written By
United Kingdom United Kingdom
Nothing interesting to report.

Comments and Discussions

 
QuestionCueText Styling Pin
TobiasVdb21-Jul-14 22:47
TobiasVdb21-Jul-14 22:47 
AnswerRe: CueText Styling Pin
cigwork26-Jul-14 21:26
cigwork26-Jul-14 21: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.