vb.net My.Settings class Category and Description

566 Views Asked by At

I am having issues with finding out exactly what my path forward should be. I would like to allow my users to be able to update the user scoped settings in the Settings.settings file in my application. I have created a form which displays these settings through a propertygrid. I would like to be able to show the description for each and maybe even assign them a category for better organization. Is there a good way to accomplish this?

Here is an example someone else had posted, but you have to make sure to include all settings. I would be afraid that I might miss one. my-settings-and-descriptions-and-getting-them-into-a-propertygrid

I guess that isn't the best reason to not use it. I also could not understand how to fully implement this option. There is also the other side of which I would like to be able to put the settings into a category instead of "Misc" like visual studio does by default.

Thanks for the help ahead of time.

J-Mo

1

There are 1 best solutions below

0
DjJazzyJeffTN On

My Solution

My goal was to be able to display all of the user-scoped settings from the settings.settings file and allow the user to be able to edit them.

Settings Form Screenshot

I added the below code directly into the Settings.Designer.vb file. I know that moving forward I will have to add all of my settings manually so as to not regenerate the code.

The added lines were:

  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

This will need to be completed for each property in the class.

The Property Grid in the form was limited to the User Scope with the below code.

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

Let me know if you have a better way of accomplishing this. It is not my preferred method with how much could go wrong.

-J-Mo