2 < config >
3 < Function Name ="a" Checked ="false" />
4 < Function Name ="b" Checked ="false" />
5 < Function Name ="c" Checked ="false" />
6 < Function Name ="d" Checked ="false" />
7 </ config >
具體的程序:需要一個CheckedListBox,兩個Button
1
Public
doc
As
New
XmlDocument
2
Public
rootnode
As
XmlElement
3
Public
strPathConfig
As
String
=
Application.StartupPath
&
"
\config.xml"
4
Public
intNum
As
Int16
5
Private
Sub
Button1_Click(
ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
6
WriteConfig()
7
End Sub
8
Private
Sub
Form1_Load(
ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
9
'
做準備工作
10
doc.Load(strPathConfig)
11
rootnode
=
doc.DocumentElement
12
intNum
=
rootnode.ChildNodes.Count
-
1
13
'
14
LoadConfig()
15
End Sub
16
'
添加到CheckedListBox
17
Function
LoadConfig()
18
Dim
i
As
Int16
19
For
i
=
0
To
intNum
20
CheckedListBox1.Items.Add(rootnode.ChildNodes(i).Attributes(
0
).Value,
CType
(rootnode.ChildNodes(i).Attributes(
1
).Value,
Boolean
))
21
Next
22
End Function
23
'
確定,然后寫入XML
24
Function
WriteConfig()
25
Dim
i
As
Int16
26
Dim
str
As
String
27
For
i
=
0
To
intNum
28
rootnode.ChildNodes(i).Attributes(
1
).Value
=
CheckedListBox1.GetItemChecked(i).ToString
29
Next
30
doc.Save(strPathConfig)
31
End Function
32
33
Private
Sub
Button2_Click(
ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
34
'
需要清除CheckedListBox內的Items
35
CheckedListBox1.Items.Clear()
36
LoadConfig()
37
End Sub
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
