(图片来源网络,侵删)
那天笔者在做项目写软件的时候,遇见了一个需要:要做一个报警指示灯,接收串口发送来的数据,当数据大于报警阈值时亮红灯,小于报警阈值时亮绿灯那就需要在软件界面窗体画一个圆圈,并在圆圈里面填充相应的颜色,然后笔者在网上查阅了大量资料,试了很多代码,一个不行再试另一个,万千尝试,终于找到了在VB.NET中画圆圈圈的代码指令,经过实践成功分享给大家以下实现了在VB.net中画圆的操作,代码供参考:Imports System.Drawing ''首先引入命名空间'----------------窗口1的类---------------Public Class Form1 '画圆子函数 Private Sub DrawCircle(ByVal cp As Point, ByVal radius As Integer, ByVal color As Brush) Dim gr As Graphics gr = Me.CreateGraphics Dim rect As Rectangle = New Rectangle(cp.X - radius, cp.Y - radius, 2 radius, 2 radius) gr.DrawEllipse(Pens.Black, rect) gr.FillEllipse(color, rect) End Sub''在本类其他子程序里面把参数改下,调用以下指令就可以画圆了''DrawCircle(New Point(300 , 15 ), 10, Brushes.Red)End Class同样地,顺便把在VB.NET中画矩形的代码分享一下Imports System.Drawing ''引入命名空间'----------------窗口1的类---------------Public Class Form1 '画矩形子函数 Private Sub DrawRectangleInt(ByVal X As Integer, ByVal Y As Integer, ByVal W As Integer, ByVal H As Integer, ByVal color As Brush) Dim bggriphic As Graphics Dim RC As Rectangle bggriphic = Me.CreateGraphics RC.X = X RC.Y = Y RC.Width = W RC.Height = H 'bggriphic.DrawRectangle(Pens.Black, RC) ''画边框 bggriphic.FillRectangle(color, RC) ''填充 End Sub''在本类其他子程序里面参数改下,调用以下指令就可以画矩形了'' DrawRectangleInt(0, 0, 100, 100, Brushes.Black)End Class
0 评论