TextBox Watermark NOT ASP.net

  • Thread starter Thread starter James
  • Start date Start date
J

James

Is there a way to put a watermark in a text box? I have sen it on web
sites but i would like to create a persistant translucent one in the
background
 
Is there a way to put a watermark in a text box? I have sen it on web
sites but i would like to create a persistant translucent one in the
background

I don't know of any easy way to do this. The "hard" way is to create a
user drawn textbox, but this gets a little funky when it comes to
selecting and deleting text.

Here's some quick code that draws a red line through the textbox:

Public Class UDtextbox
Inherits TextBox

Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics = e.Graphics
g.DrawLine(Pens.Red, 0, 3, Me.Width, 3)
g.Dispose()
End Sub

End Class

Good luck!

Thanks,

Seth Rowe
 
Would there be a way to but translucent text behind the text box that
will allow other more opaque text in from of it?
 
Would there be a way to but translucent text behind the text box that
will allow other more opaque text in from of it?

Replace g.DrawLine with g.DrawString.

Thanks,

Seth Rowe
 
Back
Top