Results 1 to 4 of 4

Thread: PlaceholderTexr

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2025
    Posts
    3

    PlaceholderTexr

    I am new to VB 2026. My laptop has Windows 11, I have reached PlaceholderTexr in the book I am following but it does not seem to work for me. I have a textbox (textbox1) and can see PlaceholderText in the properties. I typed "Please enter you name" into the property and that appeared in the textbox but when I ran the program the textbox was empty. I also tried the line textbox1.PlaceholderTexr = "Please enter you name" in the Form Load event but the box was still empty when I ran the code.

    Am I missing something?

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    Re: PlaceholderTexr

    By design, when a TextBox has focus (contains the blinking cursor), the placeholder text will disappear.

    I would place some dummy control on your form, such as a button, that does nothing. But then, when you run your program, if you click the button, which will give the button focus instead of the TextBox, the placeholder text should re-appear.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: PlaceholderTexr

    In VB.Net there are API functions available for Windows tricks like this...

    Code:
    Public Class Form1
    
        Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As IntPtr
    
        Private Const EM_SETCUEBANNER As Integer = &H1501
        Dim retainOnFocus As New IntPtr(1)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                   
            SendMessage(TextBox1.Handle, EM_SETCUEBANNER, retainOnFocus, "First Name")
            SendMessage(TextBox2.Handle, EM_SETCUEBANNER, retainOnFocus, "Last Name")
        End Sub
    
    End Class

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,509

    Re: PlaceholderTexr

    You can just set the forms "ActiveControl" property to Nothing in the the forms Shown event.

    Code:
        Private Sub Form3_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Me.ActiveControl = Nothing
    
        End Sub

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