|
private void Form1_Load(object sender, EventArgs e)
{
designer = new Designer();
designer.BeginLoad(typeof(Form));
if (!designer.IsLoaded)
throw new Exception("Le concepteur n'a pu être chargé");
((Control)designer.View).Dock = DockStyle.Fill;
panel1.Controls.Add((Control)designer.View);
// Select the service IDesignerHost
System.ComponentModel.Design.IDesignerHost host =
(System.ComponentModel.Design.IDesignerHost)
designer.GetService(typeof(System.ComponentModel.Design.IDesignerHost));
// Create a button
IComponent button = host.CreateComponent(typeof(Button));
((Control)button).Location = new Point(5, 10);
((Control)button).Text = "Bouton";
// Add it at control container
((Form)host.RootComponent).Controls.Add((Control)button);
// Create a textbox
IComponent textBox = host.CreateComponent(typeof(TextBox));
((TextBox)textBox).Location = new Point(5, 50);
// Add it at control container
((Form)host.RootComponent).Controls.Add((Control)textBox);
}
|