📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
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
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents mReg As System.Windows.Forms.MenuItem
Friend WithEvents mBuild As System.Windows.Forms.MenuItem
Friend WithEvents mRead As System.Windows.Forms.MenuItem
Friend WithEvents mModify As System.Windows.Forms.MenuItem
Friend WithEvents mBlank As System.Windows.Forms.MenuItem
Friend WithEvents mExit As System.Windows.Forms.MenuItem
Friend WithEvents mHelp As System.Windows.Forms.MenuItem
Friend WithEvents mAbout As System.Windows.Forms.MenuItem
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents btDel As System.Windows.Forms.Button
Friend WithEvents btModify As System.Windows.Forms.Button
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents btAdd As System.Windows.Forms.Button
Friend WithEvents btRead As System.Windows.Forms.Button
Friend WithEvents btExit As System.Windows.Forms.Button
Friend WithEvents mDel As System.Windows.Forms.MenuItem
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mHelp = New System.Windows.Forms.MenuItem()
Me.mAbout = New System.Windows.Forms.MenuItem()
Me.mDel = New System.Windows.Forms.MenuItem()
Me.btExit = New System.Windows.Forms.Button()
Me.mRead = New System.Windows.Forms.MenuItem()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.btDel = New System.Windows.Forms.Button()
Me.btModify = New System.Windows.Forms.Button()
Me.btAdd = New System.Windows.Forms.Button()
Me.btRead = New System.Windows.Forms.Button()
Me.mBuild = New System.Windows.Forms.MenuItem()
Me.mBlank = New System.Windows.Forms.MenuItem()
Me.MainMenu1 = New System.Windows.Forms.MainMenu()
Me.mReg = New System.Windows.Forms.MenuItem()
Me.mModify = New System.Windows.Forms.MenuItem()
Me.mExit = New System.Windows.Forms.MenuItem()
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'mHelp
'
Me.mHelp.Index = 1
Me.mHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mAbout})
Me.mHelp.Shortcut = System.Windows.Forms.Shortcut.CtrlH
Me.mHelp.ShowShortcut = False
Me.mHelp.Text = "帮助(&H)"
'
'mAbout
'
Me.mAbout.Index = 0
Me.mAbout.Shortcut = System.Windows.Forms.Shortcut.CtrlA
Me.mAbout.Text = "关于对注册表的操作(&A)..."
'
'mDel
'
Me.mDel.Index = 3
Me.mDel.Shortcut = System.Windows.Forms.Shortcut.CtrlD
Me.mDel.Text = "删除(&D)"
'
'btExit
'
Me.btExit.Location = New System.Drawing.Point(144, 144)
Me.btExit.Name = "btExit"
Me.btExit.TabIndex = 1
Me.btExit.Text = "退出(&X)"
'
'mRead
'
Me.mRead.Index = 1
Me.mRead.Shortcut = System.Windows.Forms.Shortcut.CtrlR
Me.mRead.Text = "读取(&R)"
'
'ListBox1
'
Me.ListBox1.ItemHeight = 12
Me.ListBox1.Location = New System.Drawing.Point(8, 8)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(112, 160)
Me.ListBox1.TabIndex = 4
'
'Panel1
'
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btExit, Me.btDel, Me.btModify, Me.ListBox1, Me.btAdd, Me.btRead})
Me.Panel1.Location = New System.Drawing.Point(8, 8)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(232, 176)
Me.Panel1.TabIndex = 5
'
'btDel
'
Me.btDel.Location = New System.Drawing.Point(144, 80)
Me.btDel.Name = "btDel"
Me.btDel.TabIndex = 1
Me.btDel.Text = "删除(&D)"
'
'btModify
'
Me.btModify.Location = New System.Drawing.Point(144, 56)
Me.btModify.Name = "btModify"
Me.btModify.TabIndex = 2
Me.btModify.Text = "修改(&M)"
'
'btAdd
'
Me.btAdd.Location = New System.Drawing.Point(144, 8)
Me.btAdd.Name = "btAdd"
Me.btAdd.TabIndex = 0
Me.btAdd.Text = "创建(&B)"
'
'btRead
'
Me.btRead.Location = New System.Drawing.Point(144, 32)
Me.btRead.Name = "btRead"
Me.btRead.TabIndex = 3
Me.btRead.Text = "读取(&R)"
'
'mBuild
'
Me.mBuild.Index = 0
Me.mBuild.Shortcut = System.Windows.Forms.Shortcut.CtrlB
Me.mBuild.Text = "创建(&B)"
'
'mBlank
'
Me.mBlank.Index = 4
Me.mBlank.Text = "-"
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mReg, Me.mHelp})
'
'mReg
'
Me.mReg.Index = 0
Me.mReg.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mBuild, Me.mRead, Me.mModify, Me.mDel, Me.mBlank, Me.mExit})
Me.mReg.Shortcut = System.Windows.Forms.Shortcut.CtrlF
Me.mReg.ShowShortcut = False
Me.mReg.Text = "注册表(&E)"
'
'mModify
'
Me.mModify.Index = 2
Me.mModify.Shortcut = System.Windows.Forms.Shortcut.CtrlM
Me.mModify.Text = "修改(&M)"
'
'mExit
'
Me.mExit.Index = 5
Me.mExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX
Me.mExit.Text = "退出(&X)"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(248, 193)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel1})
Me.MaximizeBox = False
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "对注册表进行操作"
Me.Panel1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub subAdd()
Dim newkey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim hareware As Microsoft.Win32.RegistryKey = newkey.OpenSubKey("HARDWARE", True)
'打开主键
Dim mynewkey As Microsoft.Win32.RegistryKey = hareware.CreateSubKey("mynewkey")
Dim subnewkey As Microsoft.Win32.RegistryKey = mynewkey.CreateSubKey("subnewkey")
'创建子键
subnewkey.SetValue("value1", "1")
subnewkey.SetValue("value2", "2")
subnewkey.SetValue("value3", "3")
subnewkey.SetValue("value4", "4")
'设定键值
MessageBox.Show("已经成功的创建注册表键及其值!", "创建成功", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'消息提示
End Sub
Private Sub subDel()
Dim newkey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim hareware As Microsoft.Win32.RegistryKey = newkey.OpenSubKey("HARDWARE", True)
'打开主键
hareware.DeleteSubKeyTree("mynewkey")
'删除子键
MessageBox.Show("已经成功的删除注册表键及其值!", "删除成功", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'消息提示
End Sub
Private Sub subModify()
Dim newkey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim hareware As Microsoft.Win32.RegistryKey = newkey.OpenSubKey("HARDWARE", True)
'打开主键
Dim mynewkey As Microsoft.Win32.RegistryKey = hareware.CreateSubKey("mynewkey")
Dim subnewkey As Microsoft.Win32.RegistryKey = mynewkey.CreateSubKey("subnewkey")
'创建子键
subnewkey.SetValue("value1", "new1")
subnewkey.SetValue("value2", "new2")
subnewkey.SetValue("value3", "new3")
subnewkey.SetValue("value4", "new4")
'修改键值
MessageBox.Show("已经成功的修改注册表的键值!", "修改成功", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'消息提示
End Sub
Private Sub subRead()
Dim newkey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim hareware As Microsoft.Win32.RegistryKey = newkey.OpenSubKey("HARDWARE")
Dim mynewkey As Microsoft.Win32.RegistryKey = hareware.OpenSubKey("mynewkey")
Dim subnewkey As Microsoft.Win32.RegistryKey = mynewkey.OpenSubKey("subnewkey")
'打开主键
Dim site As String
For Each site In subnewkey.GetValueNames()
ListBox1.Items.Add("" + site + ": " + subnewkey.GetValue(site))
Next
'读取键值并添加到ListBox1中
MessageBox.Show("已经成功的读取注册表的键值!", "读取成功", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'消息提示
End Sub
Private Sub subExit()
Application.Exit()
'退出应用程序
End Sub
Private Sub btAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAdd.Click
subAdd()
'调用添加函数
End Sub
Private Sub btRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btRead.Click
subRead()
'调用读取函数
End Sub
Private Sub btModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btModify.Click
subModify()
'调用修改函数
End Sub
Private Sub btDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDel.Click
subDel()
'调用删除函数
End Sub
Private Sub mBuild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mBuild.Click
subAdd()
'调用添加函数
End Sub
Private Sub btExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btExit.Click
subExit()
'调用退出函数
End Sub
Private Sub mExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mExit.Click
subExit()
'调用退出函数
End Sub
Private Sub mRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mRead.Click
subRead()
'调用读取函数
End Sub
Private Sub mModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mModify.Click
subModify()
'调用修改函数
End Sub
Private Sub mDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mDel.Click
subDel()
'调用删除函数
End Sub
Private Sub mAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAbout.Click
Dim fAbout As New formAbout()
fAbout.Show()
'“关于”窗口
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -