一点有用的东西

oluckly oluckly 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Imports System.Drawing

Public Class Form1

Public Structure StaticValue
Public Value As Integer
Public CurrentTime As String
End Structure

'Public Structure CPUStatics
' Public MinY As Integer
' Public MaxY As Integer
Public CriticalLine As Integer
Public StaticValues As new ArrayList
Public RefreshRate As Integer

'End Structure

' Private CPUStatic As CPUStatics
Public Const UNITDISTANCE = 10
Public Const UNITPOINTS = 4
Public CPUBitmap As Bitmap
Public g As Drawing.Graphics
Public rdm As New Random()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CriticalLine = 90
RefreshRate = 1000
Timer1.Interval = RefreshRate
Timer1.Enabled = True
DrawCurve()
End Sub

Sub DrawCurve()
Dim CPUPoints() As PointF
If StaticValues.Count <= 0 Then Exit Sub

ReDim CPUPoints(StaticValues.Count - 1)
Dim TotalLength As Integer = PictureBox1.Width / UNITPOINTS

If TotalLength > CPUPoints.Length Then
For i As Integer = TotalLength - CPUPoints.Length To TotalLength - 1
CPUPoints(i - (TotalLength - CPUPoints.Length)).X = UNITPOINTS * i
CPUPoints(i - (TotalLength - CPUPoints.Length)).Y = PictureBox1.Height - StaticValues(i - (TotalLength - CPUPoints.Length)).Value * PictureBox1.Height / 100
Next
Else
For i As Integer = 0 To TotalLength - 1
CPUPoints(i - (TotalLength - CPUPoints.Length)).X = UNITPOINTS * i
CPUPoints(i - (TotalLength - CPUPoints.Length)).Y = PictureBox1.Height - StaticValues(i - (TotalLength - CPUPoints.Length)).Value * PictureBox1.Height / 100
Next
End If

g.Clear(Color.Black)
g.DrawLine(Pens.LightGreen, 0, PictureBox1.Height Mod UNITDISTANCE, _
PictureBox1.Width, PictureBox1.Height Mod UNITDISTANCE)
For i As Integer = PictureBox1.Height Mod UNITDISTANCE To PictureBox1.Height Step UNITDISTANCE
g.DrawLine(Pens.DarkGreen, 0, i, PictureBox1.Width, i)
Next

For i As Integer = UNITDISTANCE To PictureBox1.Width Step UNITDISTANCE
g.DrawLine(Pens.DarkGreen, i, 0, i, PictureBox1.Height)
Next

'draw critical line using RED color
Dim CriticalY As Integer = PictureBox1.Height - PictureBox1.Height * CriticalLine / 100
g.DrawLine(New Pen(Color.Crimson, 2.0), 0, CriticalY, PictureBox1.Width, CriticalY)

If Not CPUPoints Is Nothing Then
If CPUPoints.Length > 1 Then
g.DrawCurve(Pens.LightYellow, CPUPoints)
End If
End If

PictureBox1.Refresh()

End Sub

Sub AddCPUVaue(ByVal CPUValue As StaticValue)
Dim tempValue As New StaticValue
tempValue = CPUValue
StaticValues.Add(tempValue)
'假设每秒产生一次数据,一天最多产生86400个
'这里只保存一天的数据
If StaticValues.Count > 86400 Then
StaticValues.RemoveAt(0)
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim CPUValue As StaticValue
CPUValue.Value = rdm.Next(50, 100)
CPUValue.CurrentTime = "1"
AddCPUVaue(CPUValue)
'Debug.Print(CPUValue.Value)
DrawCurve()

End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Not CPUBitmap Is Nothing Then CPUBitmap.Dispose()
CPUBitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
g = Drawing.Graphics.FromImage(CPUBitmap)
PictureBox1.Image = CPUBitmap
PictureBox1.Refresh()

End Sub
End Class
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
oluckly
VB基础类 7,788 成员 197,583 内容