vb.net - 在图形用户界面中更改“灯”颜色指示器 (Visual 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,并且根据返回,网络单选按钮“点”将颜色更改为绿色或红色,
推荐阅读
- tpm - 从 TPM2 模块中获取持久字符串
- c++11 - C++11 及更高版本中的异常安全和并发性:STL 实现函数的指南
- jmeter - JMETER 5.1.1:合并来自同一会话的相同采样器(与 JMETER 3.2 一样)
- php - 检测到服务的循环参考
- java - 给定一个全为 0 的二进制字符串,将其隐藏在目标字符串中
- java - 在 java 中,System.out.println 方法如何在静态和非静态上下文中工作?
- c - 为什么使用 \"%s\" 时 sprintf 不起作用?
- android - 当应用程序来自后台时始终触发观察者
- angular - 嵌套子项的 ngxs 状态更改
- node.js - 通过 SmartAdmin 项目调试 Gulp Build 失败