Properties Box

Remember the InputBox from Visual Basic? It asked the user a question and allowed him/her to type a one line string response. The PropertiesBox takes this idea even further. Given any object, the PropertiesBox displays a dialog allowing the user to edit the public properties of the object using the standard PropertyGrid control.

Design note: Although, in some cases, the PropertiesBox eliminates the need to create a custom dialog for obtaining data from the user, it should not be over used.

How It Works

The PropertiesBox class behaves much like the System.Windows.Forms.MessageBox except it can be used to input objects rather than just display string messages.

If you define the following type,

class SampleType { [Description("The first integer."), Category("Primatives")] public int Integer1 { get; set; } [Description("The second integer."), Category("Primatives")] public int Integer2 { get; set; } [Description("The first string."), Category("Objects")] public string String1 { get; set; } [Description("The first DateTime."), Category("Objects")] public DateTime DateTime1 { get; set; } }

and call,

SampleType foo; PropertiesBox.Show(foo, "Configure the complex type.", "Complex Type Configuration", PropertiesBoxOptions.Categorized);

You will get a dialog that looks like this:

Download

 

© 2010 Emil Stefanov
About this Website