Imports System.ComponentModel
Imports System.Drawing
Imports System.WinForms
Public Class Form1
Inherits System.WinForms.Form
Public Sub New()
MyBase.New
Form1 = Me
'This call is required by the Win Form Designer.
InitializeComponent
'TODO: Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Overrides Public Sub Dispose()
MyBase.Dispose
components.Dispose
End Sub
下面这些
#Region " Windows Form Designer generated code "
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
Private WithEvents Label2 As System.WinForms.Label
Private WithEvents Label1 As System.WinForms.Label
Private WithEvents TextBox2 As System.WinForms.TextBox
Private WithEvents Button4 As System.WinForms.Button
Private WithEvents Button3 As System.WinForms.Button
Private WithEvents TextBox1 As System.WinForms.TextBox
Private WithEvents Button1 As System.WinForms.Button
Private WithEvents RadioButton2 As System.WinForms.RadioButton
Private WithEvents RadioButton1 As System.WinForms.RadioButton
Dim WithEvents Form1 As System.WinForms.Form
'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.
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.TextBox1 = New System.WinForms.TextBox()
Me.TextBox2 = New System.WinForms.TextBox()
Me.Label2 = New System.WinForms.Label()
Me.Label1 = New System.WinForms.Label()
Me.Button4 = New System.WinForms.Button()
Me.RadioButton1 = New System.WinForms.RadioButton()
Me.Button3 = New System.WinForms.Button()
Me.Button1 = New System.WinForms.Button()
Me.RadioButton2 = New System.WinForms.RadioButton()
'@design Me.TrayHeight = 0
'@design Me.TrayLargeIcon = False
'@design Me.TrayAutoArrange = True
TextBox1.Location = New System.Drawing.Point(184, 80)
TextBox1.Multiline = True
TextBox1.TabIndex = 3
TextBox1.Size = New System.Drawing.Size(144, 24)
TextBox2.Location = New System.Drawing.Point(184, 128)
TextBox2.Multiline = True
TextBox2.TabIndex = 7
TextBox2.Size = New System.Drawing.Size(144, 24)
Label2.Location = New System.Drawing.Point(64, 192)
Label2.Text = "Label2"
Label2.Size = New System.Drawing.Size(264, 32)
Label2.TabIndex = 9
Label1.Location = New System.Drawing.Point(16, 184)
Label1.Text = "当前位置"
Label1.Size = New System.Drawing.Size(40, 32)
Label1.TabIndex = 8
Button4.Location = New System.Drawing.Point(8, 152)
Button4.Size = New System.Drawing.Size(168, 24)
Button4.TabIndex = 6
Button4.Text = "读取数据"
RadioButton1.Location = New System.Drawing.Point(8, 8)
RadioButton1.Text = "写入HKEY_CURRENT_USER "
RadioButton1.Size = New System.Drawing.Size(168, 24)
RadioButton1.TabIndex = 0
Button3.Location = New System.Drawing.Point(8, 112)
Button3.Size = New System.Drawing.Size(168, 24)
Button3.TabIndex = 5
Button3.Text = "写入数据"
Button1.Location = New System.Drawing.Point(8, 80)
Button1.Size = New System.Drawing.Size(168, 24)
Button1.TabIndex = 2
Button1.Text = "打开注册表子项(subkey)"
RadioButton2.Location = New System.Drawing.Point(8, 40)
RadioButton2.Text = "写入HKEY_LOCAL_MACHINE "
RadioButton2.Size = New System.Drawing.Size(168, 40)
RadioButton2.TabIndex = 1
Me.Text = "Form1"
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(336, 277)
Me.Controls.Add(Label2)
Me.Controls.Add(Label1)
Me.Controls.Add(TextBox2)
Me.Controls.Add(Button4)
Me.Controls.Add(Button3)
Me.Controls.Add(TextBox1)
Me.Controls.Add(Button1)
Me.Controls.Add(RadioButton2)
Me.Controls.Add(RadioButton1)
End Sub
#End Region
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
textbox2.Text = getval("数值项").ToString
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
writeval("数值项", textbox2.Text) : textbox2.Text = "已写入到注册表"
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If objkey = Nothing Then
msgbox("请先在上面选定注册表根项")
Me.RadioButton1.Select()
OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser)
label2.Text = objkey.ToString
Exit Sub
End If
newsubkey(textbox1.Text)
label2.Text = objkey.ToString
End Sub
Protected Sub RadioButton2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
openbasekey(Microsoft.Win32.RegistryHive.LocalMachine)
label2.Text = objkey.ToString
End Sub
Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser)
label2.Text = objkey.ToString
End Sub
End Class
'##################################################################################################################
Public Module RWregKey
'定义一个objKey 的注册项对象
Public objKey As Microsoft.Win32.RegistryKey
'_________________________________________________________________________________________________________________
'使用openremotebasekey方法打开一个注册表根项目,使用rgistryhive获取一个最上层的Key 根项目
Public Sub OpenBaseKey(ByVal basekey As Microsoft.Win32.RegistryHive)
objkey = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(basekey, SystemInformation.ComputerName)
End Sub
'__________________________________________________________________________________________________
'使opensubkey打开一个指定的子项目,
Public Sub NextSubKey(ByVal keyname As String, ByVal writeable As Boolean)
objkey = objkey.OpenSubKey(keyname, writeable) '后面的布尔值(True,false)指定是否可读写 If objkey = keytemp Then
End Sub
'____________________________________________________________________________________________________________
'_______________________________________________________________________________________________________
'如果找不到就创造一个新的subkey子项目
Public Sub NewSubKey(ByVal keyname As String)
objkey = objKey.CreateSubKey(keyname) '在这里我们创造了一个新的subkey(项)
End Sub
'____________________________________________________________________________________________________________________
'写入需要保存的数据-------ValueData
Public Sub writeVal(ByVal valname As String, ByVal valdata As Object)
objkey.SetValue(valname, valdata) '写入数据----ValueData
End Sub
' ____________________________________________________________________
'读取保存的数据
Public Function getval(ByVal valname As String) As Object
Return objKey.GetValue(valname)
End Function
'_________ '删除一个注册表项
Public Sub delKey(ByVal keyname As String)
objkey.DeleteSubKey(keyname)
End Sub
'___________________________________________________________________________________________________________()
'____________________________________________________________________________________________________________________
'删除一个数据------ValueData
Public Sub delval(ByVal valname As String)
objkey.DeleteValue(valname) '删除了一个值
objkey.Close() '记住在使用过后把他关闭,这通常是被提倡的好习惯。
End Sub
End Module
大家看了是不是很简单,我曾在论坛看到人说,VB6用得很好我为什么要用VB.Net.而且Net只是Net技术,
我们的这个……..不相关。这
真是天大的误解。
就因为后面带了一个net,大家都不理解并疏远他,不论怎么样,VB.Net因为面向对象可以更有效率的写程序。
大家为什么要拒绝呢?
我的系列文单出来以后,学VB.Net的人也增加了不少,我在网易论坛看到一个网友说为了装VB.Net装了一下午没装上,
后来我告诉他到我的网站立马搞定了。
所以我并不反对张贴我的文章(我自已在讨论组宣传VB.Net又有打广告的嫌疑),可是你总要跟我打个招呼吧?
我没有私心,一心为大家,可你们为什么要
把我的名字与网址隐藏起来呢?
更有甚者,竟公然把文章作者换成自已的名字(在网易我的《VB.Net图解入门》《一步一步安装VB.Net》竟被改成"作者:大头鬼"
,---已被管理员删了!,)。看到这些,我的心里有点凉。前几天因为网速太慢,我通宵申请了一个高
速的网站,连夜上传所有资料,谁知上传又奇慢,两天,在网上呆了十几个小时。
希望大家不要再这样的打击我了 ,这不是什么名利的问题,而是一个人起码的
尊严被杜渎了。