I have a Form, SkinForm, that uses this in the ctor:
m_surface = new DesignSurface();
IServiceContainer serviceContainer =
m_surface.GetService(typeof(IServiceContainer)) as IServiceContainer;
serviceContainer.AddService(typeof(IToolboxService ), toolbox1.Service);
serviceContainer.AddService(typeof(INameCreationSe rvice), new
NameCreationService());
serviceContainer.AddService(typeof(System.Windows. Forms.PropertyGrid),
Program.GetMainForm().GetPropertyGrid());
m_host = m_surface.GetService(typeof(IDesignerHost)) as IDesignerHost;
Control form = (Control)m_host.CreateComponent(typeof(MyDesignFor m));
// Set SelectionService - SelectionChanged event handler
m_selectionService = (ISelectionService)(serviceContainer.GetService(ty
peof(ISelectionService)));
m_selectionService.SelectionChanged += new
EventHandler(selectionService_SelectionChanged);
m_view = m_surface.View as Control;
m_view.Dock = DockStyle.Fill;
m_view.Parent = this;
This form is created by a mainform. The mainform has a toolbox and a
propertygrid. I can drag controls onto the SkinForm and select each and see
properties. The problem is that I dont exactly know how to create controls
at runtime and place them on the SkinForm so that they can be selected and
the properties show in the propertygrid. The controls typically would be
loaded from a database when the form loads. I have tried the following and
the controls show up, but they cannot be selected:
MyDesignForm frm = m_host.RootComponent as MyDesignForm;
frm.SetBitmap(m_Bitmap);
foreach (SkinButton button in m_skin.m_buttons)
{
Control clone = m_host.CreateComponent(button.GetType()) as Control;
clone = button;
frm.Controls.Add(clone);
}
What am I doing wrong? Can someone tell me how to make this work?