cottonmouth

Hi all,

I am creating a custom user control (inherited from System.Windows.Forms.UserControl) and I want to allow users to modify its properties from the designer view. I've provided public properties and so far they appear in the property window. However, I also need to support these two behaviors below:

1. When any of the custom control's properties is selected in the property window, the property's documentation must appear at the property window's bottom part, like what happens when the properties inherited from UserControl are selected.

2. Some of the custom control's properties are classes or structs. I need to be able to show an expandable item in the property window to allow the user to set the properties of these classes/structs. Currently, classes and structs properties appear on the propery window (with only their names appearing on the value cell) but are disabled.

Do you guys have any idea on how to do it

I hope I defined my problem clearly. Thank you very much.



Re: Windows Forms General Custom UserControl's Property Window

~rabin

Below are the solutions to your problems:

1) Place a Description attribute on your property:
Code Block

[Description("Here goes the description.")]
public string MyProperty
{

//place get/set here.

}


2) In this case you have two options to get the desired effect,
i)
Derive the class you are using custom control's property from UserControl, this will display the public properties of your class in the properties window, plus all the public properties of the UserControl class as well.
If you want an easier way, this is the option. But it will be slightly messy, as all the Properties of UserControl will also be visible in the properties class.

Code Block

public class MyClass : UserControl //derive the class from UserControl

{

private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
}

//this is the actual control, that will be placed in the UI
public class MyControl : UserControl
{
MyClass obj = new MyClass()

public MyClass ClassValue //this will be visible in the properties window of Control MyControl.
{
get { return this.obj; }
set { this.obj = value; }
}
}


ii)
This is the better option, but is harder to implement. In this method you have to create and use the UI Type Editors. It's not feasible to put down the code here. So here are some links that'll give you an idea how to do it.


http://msdn2.microsoft.com/en-us/library/ms171840.aspx

http://en.csharp-online.net/Design-Time_Integration%E2%80%94UI_Type_Editors





Re: Windows Forms General Custom UserControl's Property Window

Marc Gravell

re UITypeEditor - not true.

For mutable types (i.e. most classes), all you need to do is add (to the class definition):

Code Block

[TypeConverter(typeof(ExpandableObjectConverter))]

public class SomeClass { }

However, for immutable types (i.e. most structs) you will find that the expanded values are disabled. To enable them, you need to give the system some means of creating a new object from the existing (and updated) values; this is often by providing your own TypeConverter, implementing GetPropertiesSupported, GetProperties, GetCreateInstanceSupported and CreateInstance

Marc






Re: Windows Forms General Custom UserControl's Property Window

markrgli

Thanks for all the help.