📄 form1.vb
字号:
Imports Microsoft.Win32
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Label7 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Label9 = New System.Windows.Forms.Label
Me.TextBox6 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.Button4 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label8 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Label7)
Me.GroupBox1.Controls.Add(Me.Label6)
Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Top
Me.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(464, 328)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "基本信息"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(32, 208)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(40, 16)
Me.Label7.TabIndex = 25
Me.Label7.Text = "值:"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(32, 240)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(40, 16)
Me.Label6.TabIndex = 24
Me.Label6.Text = "项:"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(80, 344)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(96, 24)
Me.Button5.TabIndex = 1
Me.Button5.Text = "CPU信息获取"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(280, 344)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(88, 24)
Me.Button6.TabIndex = 2
Me.Button6.Text = "关闭"
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(32, 296)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(40, 16)
Me.Label9.TabIndex = 37
Me.Label9.Text = "项:"
'
'TextBox6
'
Me.TextBox6.Location = New System.Drawing.Point(72, 296)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.Size = New System.Drawing.Size(240, 21)
Me.TextBox6.TabIndex = 36
Me.TextBox6.Text = ""
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(72, 232)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(240, 21)
Me.TextBox5.TabIndex = 35
Me.TextBox5.Text = ""
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(352, 296)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(80, 24)
Me.Button4.TabIndex = 34
Me.Button4.Text = "删除"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(352, 200)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(80, 24)
Me.Button3.TabIndex = 33
Me.Button3.Text = "读取"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(352, 104)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(80, 24)
Me.Button2.TabIndex = 32
Me.Button2.Text = "设置"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 48)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 24)
Me.Button1.TabIndex = 31
Me.Button1.Text = "创建"
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(72, 200)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(240, 21)
Me.TextBox4.TabIndex = 30
Me.TextBox4.Text = ""
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(72, 136)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(240, 21)
Me.TextBox3.TabIndex = 29
Me.TextBox3.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(72, 104)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(240, 21)
Me.TextBox2.TabIndex = 28
Me.TextBox2.Text = ""
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(32, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(280, 21)
Me.TextBox1.TabIndex = 27
Me.TextBox1.Text = ""
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(32, 264)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(144, 16)
Me.Label8.TabIndex = 26
Me.Label8.Text = "指定要删除的注册表值"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(32, 176)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(144, 16)
Me.Label5.TabIndex = 23
Me.Label5.Text = "指定要读取的注册表值"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(32, 136)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(40, 16)
Me.Label4.TabIndex = 22
Me.Label4.Text = "值:"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(32, 104)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(40, 16)
Me.Label3.TabIndex = 21
Me.Label3.Text = "项:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(32, 80)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(144, 16)
Me.Label2.TabIndex = 20
Me.Label2.Text = "指定要设置的注册表值"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(32, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(224, 16)
Me.Label1.TabIndex = 19
Me.Label1.Text = "要创建的HKEY_CURRENT_USER注册表项"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(464, 382)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.TextBox6)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.GroupBox1)
Me.Name = "Form1"
Me.Text = "注册表操作程序"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim reg As RegistryKey
If TextBox1.Text = "" Then
MessageBox.Show("请输入注册表项!", "操作注册表")
Exit Sub
End If
'创建注册表
reg = Registry.CurrentUser.CreateSubKey(TextBox1.Text)
MessageBox.Show("注册表项" & reg.Name & "已成功创建", "创建成功")
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Me.Dispose()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim reg As RegistryKey
Try
'打开注册表
reg = Registry.CurrentUser.OpenSubKey(TextBox1.Text, True)
reg.SetValue(TextBox2.Text, TextBox3.Text)
MessageBox.Show("注册表值" & TextBox2.Text & " =" & TextBox3.Text & "已保存", "设置成功")
reg.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim reg As RegistryKey
Try
'打开注册表
reg = Registry.CurrentUser.OpenSubKey(TextBox1.Text, True)
TextBox5.Text = reg.GetValue(TextBox4.Text)
reg.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim reg As RegistryKey
If MessageBox.Show("确定要删除注册表值" & TextBox1.Text & " -" & TextBox6.Text & "吗?", "确认删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
Exit Sub
End If
Try
reg = Registry.CurrentUser.OpenSubKey(TextBox1.Text, True)
reg.DeleteValue(TextBox6.Text)
MessageBox.Show("注册表值" & TextBox1.Text & " -" & TextBox6.Text & "已删除", "删除成功")
reg.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim INfo As New FrmCPUInfo
INfo.Show()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -