0

有人可以帮我将其转换为 vb.net 2010 代码。我有一个带有 textbox1 的窗口,我发现这个代码 bt cldnt 图我可以在 vb.net 2010 中编写它

Imports System.Diagnostics

Module Module1
    Sub Main()
        Dim pc As New PerformanceCounterCategory("Network Interface")
        Dim instance As String = pc.GetInstanceNames(0)
        Dim bs As New PerformanceCounter("Network Interface", "Bytes Sent/sec", instance)
        Dim br As New PerformanceCounter("Network Interface", "Bytes Received/sec", instance)
        Console.WriteLine("Monitoring " & instance)
        Do
            Dim kbSent As Integer = bs.NextValue() / 1024
            Dim kbReceived As Integer = br.NextValue() / 1024
            Console.WriteLine(String.Format("Bytes Sent {0}k Bytes Received {1}k", kbSent, kbReceived))
            Threading.Thread.Sleep(1000)
        Loop
    End Sub
End Module
4

1 回答 1

0

它看起来像一个控制台应用程序,

您可能正在苦苦挣扎的是如何将数据放入您的文本框中?在您的示例中,它被写入控制台窗口。

只需更改这些行,您就可以了。

Console.WriteLine("Monitoring " & instance)

将以上内容更改为:

Texbox1.text = "Monitoring " & instance & vbcrlf

也改变这一行

Console.WriteLine(String.Format("Bytes Sent {0}k Bytes Received {1}k", kbSent, kbReceived))

将其更改为:

Textbox1.Text = Textbox1.Text & String.Format("Bytes Sent {0}k, Bytes Received {1}k", kbSent, kbReceived)
于 2013-04-26T18:14:28.193 回答