You're just missing a Refresh at the end of the DisableWaterMark sub:
Private Sub DisableWaterMark()
Me.waterMarkTextEnabled = False
Me.SetStyle(ControlStyles.UserPaint, False)
If oldFont IsNot Nothing Then
Me.Font = New System.Drawing.Font(oldFont.FontFamily, oldFont.Size, oldFont.Style, oldFont.Unit)
End If
Refresh()
End Sub
EDIT:
Rather than using the UserPaint control style, you can handle the WM_PAINT message in WndProc, and only print the watermark if the text is empty. The result is basically the same though.
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
Const WM_PAINT As Integer = &HF
If m.Msg = WM_PAINT Then
If Text.Length <> 0 Then
Return
End If
Using g As Graphics = Me.CreateGraphics
g.DrawString("Water Mark", Me.Font, Brushes.LightGray, 0, 0)
End Using
End If
End Sub
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
Invalidate()
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
MyBase.OnLostFocus(e)
Invalidate()
End Sub
Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
MyBase.OnFontChanged(e)
Invalidate()
End Sub
Patrick McDonald
2009-03-18 14:56:42