Hello, Just came across your interesting question. If I got it write, I think you need to deal with inherited controls and a customzied property editor. I will try to give you an idea of how you can solve your problem, but will not sneak into the time costing details (I will mark them for you).
ArjenGroeneveld wrote:
like to create a Label control
What you need first is a custom label which derives from Forms.Label.
public class LabelExtended : System.Windows.Forms.Label
{
...
}
ArjenGroeneveld wrote:
One the respective control is set in Design time,
To make it easy (for me), I will use a string property to hold the name of this selected control (how we do this will be next).
private string selectedControlName = string.Empty;
[
CategoryAttribute("Arjens Properties"),
DescriptionAttribute("Holds the name of the selected control."),
DefaultValueAttribute(""),
EditorAttribute(typeof(SelectControlEditor), typeof(UITypeEditor)) // this is the key
]
public string SelectedControlName
{
get { return selectedControlName; }
set { selectedControlName = value; }
}
ArjenGroeneveld wrote:
an property in which I can select the available controls on the Form (except for the Label controls).
We just added an EditorAttribute to the property. This is a type of SelectControlEditor and derives from UITypeEditor, which we have to create now.
using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.ComponentModel;
using System.Drawing.Design;
...
public class SelectControlEditor : UITypeEditor
{
...
}
What I want to show you is a DropDown editor, where you are able to select a control out of a list of control names. First we give the editor class the information about the DropDown, by overriding the GetEditStyle method like this:
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if( context != null ) return UITypeEditorEditStyle.DropDown;
return base.GetEditStyle(context);
}
Now we need to tell the editor how to edit your property, by overriding the EditValue method.
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provid