0

我在找出我的前进道路到底应该是什么方面遇到了问题。我想让我的用户能够在我的应用程序的 Settings.settings 文件中更新用户范围的设置。我创建了一个通过属性网格显示这些设置的表单。我希望能够显示每个的描述,甚至可能为它们分配一个类别以便更好地组织。有没有什么好方法可以做到这一点?

这是其他人发布的示例,但您必须确保包含所有设置。我会害怕我会错过一个。我的设置和描述以及将它们放入属性网格

我想这不是不使用它的最佳理由。我也无法理解如何完全实现这个选项。还有另一面,我希望能够将设置放入一个类别,而不是像 Visual Studio 默认情况下那样的“杂项” 。

感谢您提前提供帮助。

杰莫

4

1 回答 1

0

我的解决方案

我的目标是能够显示来自 settings.settings 文件的所有用户范围的设置,并允许用户能够编辑它们。

设置表单截图

我将以下代码直接添加到Settings.Designer.vb文件中。我知道继续前进,我将不得不手动添加所有设置,以免重新生成代码。

添加的行是:

  1. Global.System.ComponentModel.DescriptionAttribute("Saves the location of the CMLs Form Location")
  2. 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-莫

于 2019-09-24T18:30:09.430 回答