VB.NET display system information

xiaoxiao2021-03-06  41

Display system information

Example statement

In this example, we get information about the information, screens, and power supplies by using the SysInfo control. The program operation results are shown in Figure 97-1.

Technical point

l Use the sysinfo control

l Get the operating system version number, power attribute

Implementation process

■ New project

Open Visual Studio.net, select "New Project", select "Visual Basic Project" in the Project Type window, select "Windows Application" in the Template window, enter "SysInfo" in the Name Domain, and then select the save path. Click "Confirm".

■ Add control

Add ten Label controls to the form (you can arrange by menu "format").

■ Setting properties

Change the text attribute of the Label control of the left column to the interface.

■ Add code

Private Sub Form1_Load (Byval E AS System.Object, Byval E AS System.Eventargs) Handles MyBase.Load

'Get the operating system platform code, where 1 means 95/98, 2 represents NT / 2000 system

Select Case Sysinfo.osplatform

Case 1

Label2.text = "windows95 / 98"

Case 2

Label2.text = "WindowsNT / 2000"

End SELECT

'Get the operating system version number

Label4.text = sysinfo.OSversion & "." & Sysinfo.osbuild

'Get the size of the desktop size

Label6.text = sysinfo.workareaheight & "x" & sysinfo.workAreawidth

'Get the power status value, 1 represents the AC power, 0 represents the battery

Select Case Sysinfo.acstatus

Case 1

Label8.text = "AC power"

Case 0

Label8.text = "battery"

End SELECT

'Get the remaining time of the battery, when the battery is an AC power, return to -1, other return 255

Select Case Sysinfo.BatterylifeTime

Case -1

Label10.Text = "Unknown"

Case Else

Label10.text = sysinfo.batterylifetime

End SELECT

End Sub

■ Run the program

Click Menu "Debug | Start" or click

Icon running program.

summary

All attributes of the sysinfo control are read-only, so we can only read in the code. You can help us create a program similar to the Windows login program by using the SysInfo control. That is, when we change the system resolution or plug in or unplug a plug-and-play device, our program can respond. Operating system information, screen setting information, and power status information can be obtained by using the SYSINFO control. Among them, the size of the screen is not included in the WINDOWS taskbar.

转载请注明原文地址:https://www.9cbs.com/read-74646.html

New Post(0)