首页 > 解决方案 > 在图形用户界面中更改“灯”颜色指示器 (Visual Studio 2019)

问题描述

我想更改图形用户界面中单个圆形指示器的颜色,以便它显示操作何时完成或何时失败['双色调绿色/红色 LED']。我查看了工具箱中的内置预设,但找不到任何东西。

因此,我将不胜感激任何帮助。

成功征兆 失败指示

标签: vb.netvisual-studio-2019

解决方案


我在 msdn.microsoft.com 论坛上找到了这段代码,当您按下 RadioButton 时,它会改变“点”中心的颜色。

Private Sub RadioButton_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles RadioButton1.Paint, RadioButton2.Paint

     If DirectCast(sender, RadioButton).Checked Then
         e.Graphics.FillEllipse(Brushes.Red, New RectangleF(2.5, 4.7, 7.2, 7.2))
     End If

所以将它合并到我的代码中,它一点也不优雅,显然还有改进的余地,但它确实有效。

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    If My.Computer.Network.Ping("192.168.0.1") Then
        RadioButton1.ForeColor = Color.Green
        RadioButton1.ForeColor = Color.Black
    Else
        RadioButton1.ForeColor = Color.Red
        RadioButton1.ForeColor = Color.Black
    End If
End Sub

Private Sub RadioButton_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles RadioButton1.Paint
    If My.Computer.Network.Ping("192.168.0.1") Then
        e.Graphics.FillEllipse(Brushes.Green, New RectangleF(2.5, 4.7, 7.2, 7.2))
    Else
        e.Graphics.FillEllipse(Brushes.Red, New RectangleF(2.5, 4.7, 7.2, 7.2))
    End If
End Sub

解释:当按下“测试网络”按钮时,它会发出网络 ping,并且根据返回,网络单选按钮“点”将颜色更改为绿色或红色,

带有 RadioButton 和 Button 的 GUI


推荐阅读