I created a class that inherit panel and then fill the panel with Textbox
. Then I try to add a watermark / placeholder in the Textbox
with this code:
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Dim sTxt As String = Me.Text
sTxt = IIf(sTxt.Length = 0, txt.Text, sTxt)
If m.Msg = &HF Then
If Not Me.Focused AndAlso String.IsNullOrEmpty(sTxt) AndAlso Not String.IsNullOrEmpty(Me.WaterMark) Then
Using g = Me.CreateGraphics()
TextRenderer.DrawText(g, Me.WaterMark, Me.Font, Me.ClientRectangle, Color.Red, Me.BackColor, TextFormatFlags.Top Or TextFormatFlags.Left)
End Using
End If
MyBase.Update()
End If
End Sub
I tried that code with Textbox
only and the WaterMark
does appear, but when I try to use it on my custom text the WaterMark
never appear. I think the problem is because WndProc
Event is never triggered because I added a Textbox
inside the panel. So how can i overrides the Panel_WndProc
to Txt_WndProc
?