vb.net CPU & RAM 显示程序

前端之家收集整理的这篇文章主要介绍了vb.net CPU & RAM 显示程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

简单的实现代码

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

猜你在找的VB相关文章