首页 > 解决方案 > How to change border color of a textbox that is inside a groupbox (if possible, through a button)

问题描述

I'm trying to make the text box inside a group box to change border color when it is empty. Example below.

enter image description here

But when I did it in group box, it only works when the form loads but the color won't change..

enter image description here

The code:

Private Sub Groupbox1_Paint(sender As Object, e As PaintEventArgs) Handles GroupBox1.Paint

    With TextBox1
        Dim p As New Pen(If(TextBox1.Text <> "", Color.White, Color.Red), 0)
        e.Graphics.DrawRectangle(p, .Left - 1, .Top - 1, .Width + 1, .Height + 1)
        p.Dispose()
    End With
End Sub

REFERENCE

https://www.youtube.com/watch?v=yRL4VqebXoU

https://visualstudiocodes.blogspot.com/2019/10/text-box-border-largest-vbnet-when.html

标签: vb.net

解决方案


推荐阅读