关于使用My.Settings的文章:
http://msdn.microsoft.com/zh-cn/library/ms379611(VS.80).aspx
1)
例如:保存窗体背景颜色的属性值
创建一个新的 Setting
项目菜单->属性
-> Settings 页面->创建一个新的
setting
Name
Type
Scope Value
myColor
System.Drawing.Color User
SkyBlue
当窗体加载时使用这个设置:
Me.BackColor = My.Settings.myColor
改变值并保存:
My.Settings.myColor = Color.AliceBlue
My.Settings.Save()
2)
另外,如果你要保存集合数据(如ListBox.Items, ComboBox.Items),需要加上System.Collections.Specialized.StringCollection
数据类型。
1.
项目->属性->设置->创建一个新的Setting
Name
ListBoxCollection
Type
System.Collections.Specialized.StringCollection (Browser and locate this type)
Scope
User
Value
(至少添加一项,作为初始化值)
2.
代码示例:
先在窗体上拖一个ListBox,TextBox,Button
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs )Handles MyBase.Load
For Each item As String In My.Settings.ListBoxCollection
ListBox1.Items.Add(item)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
If TextBox1.Text <> "" And ListBox1.Items.Contains(TextBox1.Text) = False Then
ListBox1.Items.Add(TextBox1.Text)
My.Settings.ListBoxCollection.Add(TextBox1.Text)
End If
End Sub
'当窗体关闭时保存设置
Private Sub Form1_FormClosed(ByVal sender _
As System.Object, ByVal e As _
System.Windows.Forms.FormClosedEventArgs) _
Handles MyBase.FormClosed
My.Settings.Save()
End Sub
End Class
如果您对我们的论坛在线支持服务有任何的意见或建议,请通过
邮件告诉我们。
立刻免费下载
MSDN 论坛好帮手