Results 1 to 3 of 3

Thread: place holder

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    place holder

    can i do this attribute in vb.net forms
    in asp placeholder (text apear in a text box when begin type this text disappear)
    place holder using vb.net with text box

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: place holder

    I believe you're referring to what I've mostly heard called a watermark, but on searching for some implementation, one of these links also claims the "official" name is cue banner. The WinForms textbox doesn't support it, but deriving from it to add the functionality is pretty simple.

    Anyway, here's the top results from a brief search, C# code though, you'll need to convert if you want to put it in your VB project:
    http://stackoverflow.com/questions/5...-forms-textbox
    http://stackoverflow.com/questions/4...ox-in-winforms

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: place holder

    Here is the VB.NET code
    Code:
    Imports System.Runtime.InteropServices
    Module CueBannerText
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Private Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
        End Function
        Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
        Private Const EM_SETCUEBANNER As Integer = &H1501
    
        Public Sub SetCueText(ByVal control As Control, ByVal text As String)
            If TypeOf control Is ComboBox Then
                Dim Edit_hWnd As IntPtr = FindWindowEx(control.Handle, IntPtr.Zero, "Edit", Nothing)
                If Not Edit_hWnd = IntPtr.Zero Then
                    SendMessage(Edit_hWnd, EM_SETCUEBANNER, 0, text)
                End If
            ElseIf TypeOf control Is TextBox Then
                SendMessage(control.Handle, EM_SETCUEBANNER, 0, text)
            End If
        End Sub
    
    End Module
    Usage
    SetCueText(TextBox1, "Enter Name here")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width