'
站在用戶的角度思考問題,與客戶深入溝通,找到博興網(wǎng)站設(shè)計與博興網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站制作、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋博興地區(qū)。
'?。?!重要:首先要添加“引用”一個dll,選擇“System?Management”;
'
Imports?Microsoft.VisualBasic
Imports?System
Imports?System.Collections.Generic
Imports?System.ComponentModel
Imports?System.Data
Imports?System.Drawing
Imports?System.Text
Imports?System.Windows.Forms
Imports?System.Management
Imports?System.IO
Namespace?WindowsApplication1
Partial?Public?Class?Form1
Inherits?Form
Public?Sub?New()
InitializeComponent()
End?Sub
Private?Sub?button1_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取CPU編號
Dim?[MyClass]?As?New?ManagementClass("Win32_Processor")
Dim?MyCollection?As?ManagementObjectCollection?=?[MyClass].GetInstances()
Dim?MyInfo?As?String?=?"當(dāng)前系統(tǒng)CPU編號是:"
Dim?MyCPUID?As?String?=?""
For?Each?MyObject?As?ManagementObject?In?MyCollection
MyCPUID?=?MyObject.Properties("ProcessorId").Value.ToString()
Exit?For
Next?MyObject
MyInfo?=?MyCPUID
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button2_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的當(dāng)前電壓
Dim?MyInfo?As?String?=?"計算機(jī)CPU的當(dāng)前電壓是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
Try
MyInfo?=?ControlChars.Lf??String.Format("CurrentVoltage?:?"??MyObject("CurrentVoltage").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Catch
End?Try
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button3_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的外部頻率
Dim?MyInfo?As?String?=?"計算機(jī)CPU的外部頻率是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
Try
MyInfo?=?ControlChars.Lf??String.Format("ExtClock?:?"??MyObject("ExtClock").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Catch
End?Try
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button4_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的二級緩存
Dim?MyInfo?As?String?=?"計算機(jī)CPU的二級緩存尺寸是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("L2CacheSize:?"??MyObject("L2CacheSize").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button5_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的制造商名稱
Dim?MyInfo?As?String?=?"計算機(jī)CPU的制造商名稱是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("Manufacturer?:?"??MyObject("Manufacturer").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button6_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的產(chǎn)品名稱
Dim?MyInfo?As?String?=?"計算機(jī)CPU的產(chǎn)品名稱是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("Name?:?"??MyObject("Name").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button7_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的版本信息
Dim?MyInfo?As?String?=?"計算機(jī)CPU的版本信息如下:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("Version:?"??MyObject("Version").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button8_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的當(dāng)前使用百分比?注意要把SQLserver或者其他耗CPU的軟件開著否則看不到效果就一直為0
Dim?MyInfo?As?String?=?"計算機(jī)CPU的當(dāng)前使用百分比是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("LoadPercentage?:?"??MyObject("LoadPercentage").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button9_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的最大時鐘頻率
Dim?MyInfo?As?String?=?"計算機(jī)CPU的最大時鐘頻率是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("MaxClockSpeed?:?"??MyObject("MaxClockSpeed").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button10_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)CPU的當(dāng)前時鐘頻率
Dim?MyInfo?As?String?=?"計算機(jī)CPU的當(dāng)前時鐘頻率是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("CurrentClockSpeed?:?"??MyObject("CurrentClockSpeed").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button11_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)的CPU地址寬度
Dim?MyInfo?As?String?=?"當(dāng)前計算機(jī)的CPU地址寬度是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("AddressWidth:?"??MyObject("AddressWidth").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
Private?Sub?button14_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)
'獲取計算機(jī)的CPU數(shù)據(jù)寬度
Dim?MyInfo?As?String?=?"當(dāng)前計算機(jī)的CPU數(shù)據(jù)寬度是:"
Dim?MySearcher?As?New?ManagementObjectSearcher("SELECT?*?FROM?Win32_Processor")
For?Each?MyObject?As?ManagementObject?In?MySearcher.Get()
MyInfo?=?ControlChars.Lf??String.Format("DataWidth?:?"??MyObject("DataWidth").ToString())
MyInfo?=?ControlChars.Lf??"========================================================="
Next?MyObject
MessageBox.Show(MyInfo,?"信息提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)
End?Sub
End?Class
把圖片存入資源,或把路徑存放變量,在a,b的click事件中加載即可
serverstring = "Server=" 服務(wù)器IP ";DataBase=" 庫名 ";Userid=" 用戶名 ";Password=" 密碼
Try
Conn = New MySqlConnection(serverstring)
Conn.Open()
MsgBox("連接成功")
Conn.Dispose()
Conn.Close()
Catch ex As Exception
MsgBox("連接失??!")
End Try
這是 mysql 的,自己改成 sql server 的就行了
如果你是建立的窗體的話,可以用一個messagebox來顯示 messagebox.show(n)如果是控制臺程序,就可以Console.write(n)
代碼已測試。
一、測試需要的INI文件。名稱為“setinfo.ini”,存放路徑為你解決方案里“Bin“文件夾的”Debug“文件夾里。
內(nèi)容:
[Location]
pnlTime.Location.X=787
pnlTime.Location.Y=0
[TopMost]
Top=True
二、操作INI文件的類。新建一個類,類中內(nèi)容為:
Public?Class?Class1
Public?Declare?Function?GetPrivateProfileString?Lib?"kernel32"?Alias?"GetPrivateProfileStringA"?_
(?_
ByVal?lpApplicationName?As?String,?_
ByVal?lpKeyName?As?String,?_
ByVal?lpDefault?As?String,?_
ByVal?lpReturnedString?As?String,?_
ByVal?nSize?As?Int32,?_
ByVal?lpFileName?As?String?_
)?As?Int32
End?Class
三、界面代碼:
Imports?System.IO?'for?path
Public?Class?Form1
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
getINI()
End?Sub
Private?Sub?getINI()
Dim?iniclass?As?New?Class1?'
Dim?myBf?As?String?'get?set_info?開辟存儲的內(nèi)存
myBf?=?New?String(CChar(""),?256)
Dim?myFN?As?String?'配置文件的文件路徑
myFN?=?Path.Combine(My.Application.Info.DirectoryPath,?"setinfo.ini")
Dim?myAN?As?String?'Application_NAME,也是Section名稱
myAN?=?Me.TextBox1.Text
Dim?myKN?As?String?'KEY_NAME,關(guān)鍵字名稱
myKN?=?Me.TextBox2.Text
Class1.GetPrivateProfileString(myAN,?myKN,?"",?myBf,?myBf.Length,?myFN)?'調(diào)用讀取INI文件的操作
TextBox3.Text?=?Microsoft.VisualBasic.Left(myBf,?InStr(myBf,?Chr(0))?-?1)?'截取有用部分,有必要
End?Sub
End?Class
四、測試截圖如下
用2個單選控件
按鈕下 如果 單選控件1狀態(tài)是選中的 就顯示窗體2 不是則顯示窗體3
或者 你可以顯示 圖像框控件2