Watermark TextBox in WinForms

前端 未结 10 1852
说谎
说谎 2020-11-22 00:35

Can anyone point me to a good implementation of a basic Windows Forms TextBox that will initially show watermark text that disappears when the cursor enters it? I think I ca

10条回答
  •  一向
    一向 (楼主)
    2020-11-22 00:58

    You can add a watermark to a Textbox (multiline or not) that works pretty well by drawing it in different controls Paint event. For Example:

        Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
            If TextBox1.Text = "" Then
                TextBox1.CreateGraphics.DrawString("Enter Text Here", Me.Font, New SolidBrush(Color.LightGray), 0, 0)
            End If
        End Sub
    

    -OO-

提交回复
热议问题