1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Public Class Form1
Private WithEvents CPU As New PerformanceCounter
Private WithEvents Ram As New PerformanceCounter
Private WithEvents Timer As New Timer With {.Interval = 500}
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.CPU.CategoryName = "Processor"
Me.CPU.CounterName = "% Processor Time"
Me.CPU.InstanceName = "_Total"
Me.Ram.CategoryName = "Memory"
Me.Ram.CounterName = "% Committed Bytes In Use"
Me.Chart1.Series.Clear()
Me.Chart1.Series.Add("CPU")
Me.Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line
Me.Chart1.Legends(0).BackColor = Color.FromArgb(224, 224, 224, 224)
Me.Chart1.ChartAreas(0).BackColor = Color.FromArgb(224, 224, 224, 224)
Me.Chart1.ChartAreas(0).AxisX.LabelStyle.Font = New Font("Times New Roman", 14, FontStyle.Bold)
Me.Chart1.ChartAreas(0).AxisX.LabelStyle.ForeColor = Color.Red
Me.Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.Red
Me.Chart1.Series(0).Color = Color.Red
Me.Chart1.Series(0).BorderWidth = 3
Me.Chart1.ChartAreas(0).AxisX.Maximum = 100
Me.Chart1.ChartAreas(0).AxisX.Minimum = 0
Me.Chart1.Series.Add("RAM")
Me.Chart1.Series(1).ChartType = DataVisualization.Charting.SeriesChartType.Line
Me.Chart1.Series(1).Color = Color.Blue
Me.Chart1.Series(1).BorderWidth = 3
Me.Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.Blue
Me.Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Times New Roman", 14, FontStyle.Bold)
Me.Chart1.ChartAreas(0).AxisY.LabelStyle.ForeColor = Color.Blue
Me.Chart1.ChartAreas(0).AxisY.Maximum = 100
Me.Chart1.ChartAreas(0).AxisY.Minimum = 0
AddHandler Timer.Tick, AddressOf Timer1_Tick
Timer.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs)
Me.MyProgressbar1.Value = CPU.NextValue
Me.MyProgressbar2.Value = Ram.NextValue
Label3.Text = MyProgressbar1.Value & " %"
Label4.Text = MyProgressbar2.Value & " %"
Chart1.Series("CPU").Points.AddY(MyProgressbar1.Value)
Chart1.Series("RAM").Points.AddY(MyProgressbar2.Value)
For i = 0 To Chart1.Series.Count - 1
If Chart1.Series(0).Points.Count = 100 Then
Chart1.Series(0).Points.RemoveAt(i)
Chart1.Series(1).Points.RemoveAt(i)
End If
Next
End Sub
End Class |