TextBox Border Blue Color Когда пусто, то Border Color Красный vb.net - PullRequest
0 голосов
/ 06 октября 2019

TextBox Border Blue Color, когда пусто, затем Border Color Red vb.net Я использую приведенный ниже код, но не работаю

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim p As New Pen(Color.Blue, 2)
        e.Graphics.DrawRectangle(p, New Rectangle(TextBox1.Location + New Size(1, 1), TextBox1.Size - New Size(2, 2)))
        p.Dispose()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then

            TextBox1.Region = New Region(New Rectangle(2, 2, TextBox1.Width - 4, TextBox1.Height - 4))
        Else
        End If
    End Sub

1 Ответ

0 голосов
/ 07 октября 2019

Вот ваш код:

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    With TextBox1
        Dim p As New Pen(If(.Text = "", Color.Red, Color.Blue), 2)
        e.Graphics.DrawRectangle(p, .Left - 1, .Top - 1, .Width + 2, .Height + 2)
        p.Dispose()
    End With
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.Invalidate()
End Sub
...