|
-
Thread Starter
New Member
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?
-
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.
-
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|