您的位置:首页 > 编程语言 > VB

vb.net CPU & RAM 显示程序

2013-06-17 21:12 351 查看
简单的实现代码:

Public Class Form1
Private PerCounter As System.Diagnostics.PerformanceCounter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PerCounter = New System.Diagnostics.PerformanceCounter
PerCounter.CategoryName = "Processor"
PerCounter.CounterName = "% Processor Time"
PerCounter.InstanceName = "_Total"

Dim nutzram As Double
nutzram = (My.Computer.Info.TotalPhysicalMemory - My.Computer.Info.AvailablePhysicalMemory) / 1048576 / 1024
Label2.Text = "RAM: " & nutzram.ToString("N") & " GB"

Dim Prozent1 As Long
Prozent1 = My.Computer.Info.AvailablePhysicalMemory * 100
Dim Prozentsatz As Long
Prozentsatz = Val(Prozent1 / My.Computer.Info.TotalPhysicalMemory)
ProgressBar2.Value = Prozentsatz

Dim i As Integer = Integer.Parse(Format(PerCounter.NextValue, "##0"))
ProgressBar1.Value = i

Label1.Text = "CPU: " & i & " %"
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim nutzram As Double
nutzram = (My.Computer.Info.TotalPhysicalMemory - My.Computer.Info.AvailablePhysicalMemory) / 1048576 / 1024
Label2.Text = "RAM: " & nutzram.ToString("N") & " GB"

Dim Prozent1 As Long
Prozent1 = My.Computer.Info.AvailablePhysicalMemory * 100
Dim Prozentsatz As Long
Prozentsatz = Val(Prozent1 / My.Computer.Info.TotalPhysicalMemory)
ProgressBar2.Value = Prozentsatz

Dim i As Integer = Integer.Parse(Format(PerCounter.NextValue, "##0"))
ProgressBar1.Value = i

Label1.Text = "CPU: " & i & " %"

End Sub
End Class


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: