Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set TextBox hint label in VB .NET?

Tags:

vb.net

In my application I have one text box for entering user name. If text is empty i want to show "Enter User name here" in same text box in gray color. Is there any property like this for text box. Like in Firefox browser if URL field is empty it will show "Go to a web site" In gray color

Thanks

like image 298
Royal Pinto Avatar asked Aug 12 '11 05:08

Royal Pinto


2 Answers

I know this may be an old thread, but I thought I'd answer it just in case anyone else stumbled across it.

First declare the following (you may need to import System.Runtime.InteropServices)

<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared 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

Then call the following (change as needed):

SendMessage(Me.textbox1.Handle, &H1501, 0, "Enter User name here")
like image 180
Grahamvs Avatar answered Sep 19 '22 22:09

Grahamvs


Assuming you mean Windows Forms, take a look at this question.
Basically, you need to call a WinAPI SendMessage function for the control with EM_SETCUEBANNERvalue.

like image 31
Dan Abramov Avatar answered Sep 18 '22 22:09

Dan Abramov