Vb.Net - Class to Change Textbox BackColor Dynamically

前端 未结 2 959
借酒劲吻你
借酒劲吻你 2021-01-15 16:51

I\'d like to know how to create a Class to change each textbox BackColor inside a Form. To be more Specific:

  1. When the textbox Is Empty, the textbox BackColor e
2条回答
  •  走了就别回头了
    2021-01-15 17:08

    All you need to do is inherit from the TextBox control.

    Public Class TextBoxEx
        Inherits TextBox
    
        Private Sub TextBoxEx_Enter(sender As Object, e As EventArgs) Handles Me.Enter
            Me.BackColor = Color.LightCyan
        End Sub
    
        Private Sub TextBoxEx_Leave(sender As Object, e As EventArgs) Handles Me.Leave
            If Me.Text <> "" Then
                Me.BackColor = Color.LightGreen
            Else
                Me.BackColor = Color.White
            End If
        End Sub
    End Class
    

    Build your project and then replace your TextBox controls with the new TextBoxEx control.

提交回复
热议问题