Skip to content

OptionTreeView is a UserControl written in .Net Framework 4.8 and .NET 8, that automatically generates options windows view. (using Settings.settings)

Notifications You must be signed in to change notification settings

avan06/OptionTreeView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

OptionTreeView is a UserControl written in .Net Framework 4.8 and .NET 8,
that automatically generates options windows view. (using Settings.settings)

Table of Contents

TOC generated by markdown-toc

Description

  • OptionTreeView will read and parse the settings in Settings.settings.
  • According to the parsing result, the settings are assigned to different trees and groups.
  • For standard type settings, trees and groups will be set to "Default".
  • After specifying the Type of settings to "OptionTreeView.Option" generic class, the settings can be categorized into the specified trees and groups.
  • Added support for export and import and restore settings feature. This feature requires ShowExportImportTreePage to be enabled.

OptionForm Managing.settings

Getting Started

Add Reference

  • Add "OptionTreeView.dll" to the reference from your project.

Drag component to Form

  • Drag the Toolbox's OptionTreeView component to the Form of your project from Design Mode.

Settings.settings

  • Starting with the .NET Framework 2.0, you can create and access values that are persisted between application execution sessions.
  • These values are called settings, Using Application Settings and User Settings
  • Create the Settings.settings file for the first time, from Solution > Project > Properties > Settings > Click here to create one.

Settings.settings

Generic(OptionTreeView.Option) in Settings

  • To make the settings have tree and group classification, the type must be changed to OptionTreeView.Option generic class.
  • Generic supported types are sbyte, short, int, long, byte, ushort, uint, ulong, decimal, float, double, Enum, bool, string and
  • System.Drawing.Color for Color Selector ComboBox.
  • System.Drawing.KnownColor for Color Picker ComboBox.
  • System.Drawing.FontFamily for Font Selector ComboBox.
  • System.Windows.Forms.KeyEventArgs for Key down event handler.
  • The Settings in the GUI Designer interface cannot set the type to a generic class, but...
  • You can open Settings.settings with XML(text) Editor, and insert the generic class inside , Refer to Generic types for Settings.settings
  • The format of the OptionTreeView.Option generic class in the setting value is: "value|TreeName|GroupName|Description|MinValue|MaxValue", use Vertical bar(|) to separate text, such as "100|general|factor|This is Description"
    "100|general|factor|This is Description|-100|200"
  • MinValue and MaxValue define the range of Value, which can be omitted.

Settings.settingsXML

  • Example of Properties\Settings.settings
<SettingsFile ...>
  <Settings>
    <Setting Name="strKey" Type="System.String" Scope="User">
      <Value Profile="(Default)">ValueKey123</Value>
    </Setting>
    <Setting Name="Enum1" Type="OptionTreeView.Option&lt;OptionTreeViewTestApp.ImageType&gt;" Scope="User">
      <Value Profile="(Default)">1|1_General|1_Enum|This is Enum1</Value>
    </Setting>
    <Setting Name="Enum2" Type="OptionTreeView.Option&lt;OptionTreeViewTestApp.ImageType&gt;" Scope="User">
      <Value Profile="(Default)">Bmp|1_General|1_Enum|This is Enum2</Value>
    </Setting>
    <Setting Name="Color1" Type="OptionTreeView.Option&lt;System.Drawing.KnownColor&gt;" Scope="User">
      <Value Profile="(Default)">CornflowerBlue|1_General|2_KnownColor|This is KnownColor1</Value>
    </Setting>
    <Setting Name="Color2" Type="OptionTreeView.Option&lt;System.Drawing.KnownColor&gt;" Scope="User">
      <Value Profile="(Default)">DarkSeaGreen|1_General|2_KnownColor|This is KnownColor2</Value>
    </Setting>
    <Setting Name="Color3" Type="OptionTreeView.Option&lt;System.Drawing.Color&gt;" Scope="User">
      <Value Profile="(Default)">DarkSeaGreen|1_General|2_KnownColor|This is Color1</Value>
    </Setting>
    <Setting Name="Color4" Type="OptionTreeView.Option&lt;System.Drawing.Color&gt;" Scope="User">
      <Value Profile="(Default)">99B4D1|1_General|2_KnownColor|This is Color2</Value>
    </Setting>
    <Setting Name="FontFamily1" Type="OptionTreeView.Option&lt;System.Drawing.FontFamily&gt;" Scope="User">
      <Value Profile="(Default)">[FontFamily: Name=Microsoft Sans Serif]|1_General|3_FontFamily|This is FontFamily1</Value>
    </Setting>
    <Setting Name="Key1" Type="OptionTreeView.Option&lt;System.Windows.Forms.KeyEventArgs&gt;" Scope="User">
      <Value Profile="(Default)">Ctrl + NumPad0|1_General|4_KeyOptions|This is Key1</Value>
    </Setting>
    <Setting Name="IP" Type="OptionTreeView.Option&lt;string&gt;" Scope="User">
      <Value Profile="(Default)">192.168.1.1|1_General|Z_Connect1|This is IP</Value>
    </Setting>
    <Setting Name="PORT" Type="OptionTreeView.Option&lt;int&gt;" Scope="User">
      <Value Profile="(Default)">80|1_General|Z_Connect1|This is PORT|0|10000</Value>
    </Setting>
    <Setting Name="Version" Type="OptionTreeView.Option&lt;float&gt;" Scope="User">
      <Value Profile="(Default)">9.99|1_General|Connect2|This is Version|0.5|10.5</Value>
    </Setting>
    <Setting Name="Type" Type="OptionTreeView.Option&lt;string&gt;" Scope="User">
      <Value Profile="(Default)">TEST|1_General|Connect2|This is Type</Value>
    </Setting>
    <Setting Name="Work3" Type="OptionTreeView.Option&lt;bool&gt;" Scope="User">
      <Value Profile="(Default)">true|1_General|Connect3|This is Work3</Value>
    </Setting>
  </Settings>
</SettingsFile>

Initialize OptionTreeView

  • Perform InitSettings method, pass your project's "Properties.Settings.Default" settings to OptionTreeView.
//In the InitializeComponent section
private OptionTreeView.OptionTreeView optionTreeView1;
optionTreeView1 = new OptionTreeView.OptionTreeView();
...
//Pass your project's "Properties.Settings.Default" settings to OptionTreeView in your code.
optionTreeView1.InitSettings(Properties.Settings.Default);

Prompt Save

  • If the value is changed, it will ask if you want to save the setting when closing the window.

Properties

  • Appearance
    ForeColorLeftView: Gets or sets the foreground color of OptionLeftView.
    BackColorLeftView: Gets or sets the background color of OptionLeftView.
    BorderStyleLeftView: Gets or sets the border style of OptionLeftView.
    FontLeftView: Gets or sets the font of OptionLeftView.
    ItemHeightLeftView: Gets or sets the height of each tree node in the OptionLeftView.

  • Behavior
    ContextMenuStripLeftView: Gets or sets the ContextMenuStrip associated with this OptionLeftView.
    FullRowSelectLeftView: Gets or sets a value indicating whether the selection highlight spans the width of OptionLeftView.
    ShowLeftView: Gets or sets whether to show the left tree view.
    ShowDefaultGroupName: Gets or sets whether to display default names of unconfigured groups. Group default with 'Default' name when the group name is not specified in Settings.settings.
    SortTreeBeforeUnderline: Determine whether to sort by the values before the underline of tree name. Default is false.
    SortGroupBeforeUnderline: Determine whether to sort by the values before the underline of group name. Default is false.
    FloatingPointDecimalPlaces: Gets or sets the number of decimal places for floating-point numbers.
    ShowToolTipDuration: Gets or sets the number containing the duration, in milliseconds, to display the ToolTip.
    InsertSpaceOnCamelCaseGroupName: Get or set whether to automatically add spaces between CamelCases of GroupName. Default is true.
    InsertSpaceOnCamelCaseLabelName: Get or set whether to automatically add spaces between CamelCases of LabelName. Default is true.
    InsertSpaceOnCamelCaseNumber: Get or set whether to automatically add spaces between CamelCases and number. Default is false. Example: Abc123DefGhi => Abc 123 Def Ghi.
    ShowExportImportTreePage: Gets or sets whether to display the export-import tree page. Default is true. DisplayChangesListWhenSaving: Gets or sets whether to display the list of change options when saving. Default is true.
    AdditionalInfoDict: Gets or sets an additional customized information Dictionary for use with options. Not used by default. The format and explanation of the Dictionary keys are as follows:

    1. tree_Name, for example, tree_General. If the tree_Name is set as the key, the value will be displayed as the Tree name(General).
    2. group_Name, for example, group_Connect. If the group_Name is set as the key, the value will be displayed as the Group name(Connect).
    3. description_OptionName, for example, description_UIFont. If the description_OptionName(UIFont) is set as the key, the value will be used as the description text for OptionName(UIFont).
    4. OptionName, for example, UIFont. If the OptionName is set as the key, the value will be displayed as the OptionName(UIFont).
  • Layout OptionLeftCollapsed: Gets or sets a value determining whether OptionLeft is collapsed or expanded.
    OptionLeftMinSize: Gets or sets the minimum distance in pixels of the OptionLeft.
    OptionRightCollapsed: Gets or sets a value determining whether OptionRight is collapsed or expanded.
    OptionRightMinSize: Gets or sets the minimum distance in pixels of the OptionRight.
    OptionRightLabelSize: Get or set the Label size in pixels of the OptionRight. Default 150.
    SplitterDistance: Gets or sets the location of the splitter, in pixels, from the left or top edge of the SplitContainer.
    SplitterIncrement: Gets or sets a value representing the increment of splitter movement in pixels.
    SplitterWidth: Gets or sets the width of the splitter in pixels.

Settings Usage and OptionTreeView.Option Class

  • Get Value
Properties.Settings.Default.VariableName.Value;
  • Set Value
Properties.Settings.Default.VariableName.Value = NewValue;
Properties.Settings.Default.Save();
  • OptionTreeView.Option Class
public class Option<dynamic> : BaseOption
{
  public dynamic Value
  {
    get => (dynamic)BaseObject;
    set
    {
      if (MinObject != null && MinObject.GetType().Name != "String" && value < MinObject) value = MinObject;
      if (MaxObject != null && MaxObject.GetType().Name != "String" && value > MaxObject) value = MaxObject;
      BaseObject = value;
    }
  }
  public Option(dynamic value, string treeName = "Default", string groupName = "Default", string description = "", object minObject = null, object maxObject = null) : base(value, treeName, groupName, description, minObject, maxObject) { }
  public override string ToString() => Value == null ? "" : Value.ToString();
}
    
public class BaseOption
{
    public dynamic BaseObject { get; set; }
    public string TreeName { get; private set; }
    public string GroupName { get; private set; }
    public string Description { get; private set; }
    public dynamic MinObject { get; private set; }
    public dynamic MaxObject { get; private set; }
    public BaseOption(dynamic baseObject, string treeName, string groupName, string description, dynamic minObject, dynamic maxObject)
    {
      BaseObject = baseObject;
      TreeName = treeName;
      GroupName = groupName;
      Description = description;
      MinObject = minObject;
      MaxObject = maxObject;
    }
}

Reference

Using Custom Classes with Application Settings
Generic types for Settings.settings (it is possible to do this by manually editing the setting XML file.)
TypeConverter for a generic type/Creating an single Converter that could hanlde all of the types derrived
TypeConverter for a generic type/An alternative solution using TypeDescriptionProviderAttribute
Cast generic type without knowing T/With reflection and without the code knowing anything about 't', the closest you can get is an interface for MyType
Cast generic type without knowing T/GetProperty and GetValue

About

OptionTreeView is a UserControl written in .Net Framework 4.8 and .NET 8, that automatically generates options windows view. (using Settings.settings)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages