我的解决方案
我的目标是能够显示来自 settings.settings 文件的所有用户范围的设置,并允许用户能够编辑它们。
设置表单截图
我将以下代码直接添加到Settings.Designer.vb文件中。我知道继续前进,我将不得不手动添加所有设置,以免重新生成代码。
添加的行是:
Global.System.ComponentModel.DescriptionAttribute("Saves the location of the CMLs Form Location")
Global.System.ComponentModel.CategoryAttribute("Location")
<Global.System.Configuration.UserScopedSettingAttribute(),
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),
Global.System.ComponentModel.DescriptionAttribute("Saves the CMLs Form Location"),
Global.System.ComponentModel.CategoryAttribute("Location"),
Global.System.Configuration.DefaultSettingValueAttribute("0, 0")>
Public Property FormCMLsLocation() As Global.System.Drawing.Point
Get
Return CType(Me("FormCMLsLocation"), Global.System.Drawing.Point)
End Get
Set
Me("FormCMLsLocation") = Value
End Set
End Property
这将需要为类中的每个属性完成。
表单中的属性网格仅限于使用以下代码的用户范围。
Public Class FormUserSettings
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim userAttr As New System.Configuration.UserScopedSettingAttribute
Dim attrs As New System.ComponentModel.AttributeCollection(userAttr)
Dim myProxy As New ProxySettings
If PropertyGrid IsNot Nothing Then
'PropertyGrid.SelectedObject = myProxy
PropertyGrid.SelectedObject = My.Settings
End If
PropertyGrid.BrowsableAttributes = attrs
End Sub
End Class
如果您有更好的方法来完成此任务,请告诉我。这不是我喜欢的方法,可能会出错。
-J-莫