Form designer cannot respond command
- From: "allen pan" <allenpan@xxxxxxxxxxxxx>
- Date: Thu, 3 Nov 2005 09:58:19 +0800
I write a simple form designer in vs2005. I can add and edit controls on
this designer. but when I delete a control, it can not repond.
the code like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DesignSurface surface = new DesignSurface();
surface.BeginLoad(typeof(Form));
Control view = (Control)surface.View;
view.Dock = DockStyle.Fill;
this.splitContainer1.Panel1.Controls.Add(view);
this.propertyGrid1.SelectedObject =
surface.ComponentContainer.Components[0];
toolBoxService = new DemoToolboxService();
toolBoxService.ToolBox = new ListBox();
toolBoxService.ToolBox.Items.Add("Point");
toolBoxService.ToolBox.Items.Add(new
ToolboxItem(typeof(Button)));
toolBoxService.ToolBox.Items.Add(new
ToolboxItem(typeof(TextBox)));
toolBoxService.ToolBox.Items.Add(new
ToolboxItem(typeof(Label)));
toolBoxService.ToolBox.Items.Add(new
ToolboxItem(typeof(TabControl)));
toolBoxService.ToolBox.Items.Add(new
ToolboxItem(typeof(StatusBar)));
toolBoxService.ToolBox.Dock = DockStyle.Fill;
this.panel1.Controls.Add(toolBoxService.ToolBox);
menuCommandService = new MenuCommandService(surface);
IServiceContainer container =
surface.GetService(typeof(IServiceContainer)) as IServiceContainer;
if (container != null)
{
container.AddService(typeof(IToolboxService),
toolBoxService);
container.AddService(typeof(IMenuCommandService),
menuCommandService);
}
selectionService = surface.GetService(typeof(ISelectionService))
as ISelectionService;
selectionService.SelectionChanged += new
EventHandler(selectionService_SelectionChanged);
}
void selectionService_SelectionChanged(object sender, EventArgs e)
{
object[] selection;
if (selectionService.SelectionCount == 0)
propertyGrid1.SelectedObject = null;
else
{
selection = new object[selectionService.SelectionCount];
selectionService.GetSelectedComponents().CopyTo(selection,
0);
propertyGrid1.SelectedObjects = selection;
}
}
private DemoToolboxService toolBoxService;
private ISelectionService selectionService;
private MenuCommandService menuCommandService;
private void deleteToolStripMenuItem_Click(object sender, EventArgs
e)
{
menuCommandService.GlobalInvoke(StandardCommands.Delete);
}
}
thank!
.
- Follow-Ups:
- RE: Form designer cannot respond command
- From: "Jeffrey Tan[MSFT]"
- RE: Form designer cannot respond command
- Prev by Date: Re: Root designer and form serialization problem
- Next by Date: Re: Position label and text in CreateComponentsCore()
- Previous by thread: Re: Root designer and form serialization problem
- Next by thread: RE: Form designer cannot respond command
- Index(es):