现在的位置: 首页 > 综合 > 正文

vb.net CPU & RAM 显示程序

2013年06月13日 ⁄ 综合 ⁄ 共 1345字 ⁄ 字号 评论关闭

简单的实现代码:

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

 

抱歉!评论已关闭.