I have a question about design-time things:
I\'ve made a component with an property \"Links\". Those links are Controls. Now I want to make a UI-Dialog (for editing this
You can get IDesignerHost service at design-time. This service has a property called Container
which has Components
. Then for each component, get INestedContainer service and then get all components from that service.
This is how Document Outline window works. I've changed their method to use List
as return value:
List GetSelectableComponents(IDesignerHost host)
{
var components = host.Container.Components;
var list = new List();
foreach (IComponent c in components)
list.Add(c);
for (var i = 0; i < list.Count; ++i)
{
var component1 = list[i];
if (component1.Site != null)
{
var service = (INestedContainer)component1.Site.GetService(
typeof(INestedContainer));
if (service != null && service.Components.Count > 0)
{
foreach (IComponent component2 in service.Components)
{
if (!list.Contains(component2))
list.Add(component2);
}
}
}
}
return list;
}
To filter the result to contain just controls, you can call result.TypeOf
.