クラスはリフレクション経由で簡単に取得できます。
var formNames = this.GetType().Assembly.GetTypes().Where(x => x.Namespace == "UI.Foo.Forms").Select(x => x.Name);
フォームと同じアセンブリ内のコードからこれを呼び出すと仮定すると、"UI.Foo.Forms" 名前空間にあるすべての型の名前が取得されます。次に、これをドロップダウンに表示し、最終的に、リフレクションを介してユーザーが選択したものをもう一度インスタンス化できます。
Activator.CreateInstance(this.GetType("UI.Form.Forms.FormClassName"));
[編集] 設計時のコードの追加:
コントロールで Form プロパティを次のように作成できます。
[Browsable(true)]
[Editor(typeof(TestDesignProperty), typeof(UITypeEditor))]
[DefaultValue(null)]
public Type FormType { get; set; }
定義する必要があるエディターの種類を参照します。コードはかなり自明であり、微調整を最小限に抑えるだけで、必要なものを正確に生成できるようになる可能性があります。
public class TestDesignProperty : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
var edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
ListBox lb = new ListBox();
foreach(var type in this.GetType().Assembly.GetTypes())
{
lb.Items.Add(type);
}
if (value != null)
{
lb.SelectedItem = value;
}
edSvc.DropDownControl(lb);
value = (Type)lb.SelectedItem;
return value;
}
}