0 people following this project (follow)

Project Description
The AdjustablePropertyGrid is a simple derivation of .NET PropertyGrid in C#. It adds two runtime properties: LabelWidth, the width of the label column, and HelpRegionSize, the height of the description region at the bottom.

These two properties are adjustable by the user at runtime using splitter bars. Making these two properties accessible programmatically allows a Windows Form that uses a PropertyGrid to save and restore the last settings selected by the user. Or the property values can simply be set as needed by the application.

Typical code to restore/save settings would look like this:

private void MainForm_Load(object sender, EventArgs e)
{
    // Read in saved per-user settings
    propGrid.HelpRegionSize = Settings.Default.HelpRegionSize;
    propGrid.LabelWidth = Settings.Default.LabelWidth;
    // other settings here...
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
    // other settings here...
    Settings.Default.LabelWidth = propGrid.LabelWidth;
    Settings.Default.HelpRegionSize = propGrid.HelpRegionSize;
    Settings.Default.Save();
}

This assumes the form has an AdjustablePropertyGrid named propGrid, and integer settings created and appropriately initialized by the Settings Designer, named LabelWidth and HelpRegionSize. Note that the units for LabelWidth are pixels, while the units for HelpRegionSize are lines of text, defaulting to 3.

This project is presented in source form only, as a single C# class file. Once you add the file to your project and successfully compile, the AdjustablePropertyGrid will be added to the Visual Studio Toolbox provided the AutoToolboxPopulate option is True. This option can be found under Tools / Options... / Windows Forms Designer / General / Toolbox. If you change the setting, you must close the solution for it to take effect. Once it's in the Toolbox, all the usual visual design capabilities available, just as if it were an ordinary PropertyGrid.

The underlying techniques for accessing these internal settings has been posted by others in the past. I've just collected them into a ready-to-use component.

Last edited Feb 1 at 12:46 AM by DosMan, version 10