加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net CPU & RAM 显示程序

发布时间:2020-12-17 08:11:51 所属栏目:百科 来源:网络整理
导读:简单的实现代码: 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.Perfo

简单的实现代码:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读