0

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?

kit
  • 1,166
  • 5
  • 16
  • 23
XMozart
  • 879
  • 2
  • 10
  • 22
  • Are you talking about a cue banner, i.e. a text prompt that appears in a muted colour in a `TextBox` until you type something into it? If so then you should make use of the Windows API intended for that specific purpose. – jmcilhinney Nov 14 '18 at 06:58
  • With that in mind, check out [this thread](https://stackoverflow.com/questions/18563522/implementing-a-cue-banner-to-a-textbox) – jmcilhinney Nov 14 '18 at 07:03

0 Answers0