Re: Form designer cannot respond command

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Allen,

I modify it as your research, it works well, thank you VERY MUCH!

Best regards,
Allen Pan


""Jeffrey Tan[MSFT]"" <v-jetan@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:DnlILfE5FHA.3936@xxxxxxxxxxxxxxxxxxxxxxxx
> Hi Allen,
>
> Sorry for letting you wait for so long.
>
> Yes, I can reproduce out this problem. I have tried to contact our product
> team for this issue, however, for more than 2 days, I did not get any
> response. Then I decided to research into myself with Reflector.
>
> After comparing the difference between .Net1.1 and .Net2.0 design-time
> service, I found that .Net2.0 provided build-in support for
> MenuCommandService, also, .Net2.0 use DesignSurface class to encapsulate
> the original function of DesignerHost and ServiceContainer. So there is no
> need for us to implement these classes in .Net2.0.
>
> Based on the debugging in this issue, I found that
> menuService.GlobalInvoke
> can not find correct menu command corresponding with
> StandardCommands.Delete. So I suspect that designer did not invoke
> MenuCommandService.AddCommand to add the delete command. While designer
> invokes invoke MenuCommandService.AddCommand in DesignSurface.BeginLoad
> method, so I finally found the root cause:
> DesignSurface can not find valid MenuCommandService in this method.
>
> Why? This is because we add MenuCommandService in a time after
> DesignSurface.BeginLoad, which is not correct. To workaround this issue,
> we
> should add MenuCommandService before invoking DesignSurface.BeginLoad.
> Changed code snippet like this:
>
> private void Form1_Load(object sender, EventArgs e)
> {
> DesignSurface surface = new DesignSurface();
>
> 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);
>
> IServiceContainer container =
> surface.GetService(typeof(IServiceContainer)) as IServiceContainer;
>
> menuCommandService = new MenuCommandService(surface);
>
> if (container != null)
> {
> container.AddService(typeof(IToolboxService), toolBoxService);
> container.AddService(typeof(IMenuCommandService),
> menuCommandService);
> }
>
> 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];
>
> selectionService = surface.GetService(typeof(ISelectionService)) as
> ISelectionService;
> selectionService.SelectionChanged += new
> EventHandler(selectionService_SelectionChanged);
> }
> After the modification, the delete function works well on my side. Hope it
> helps
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>


.


Quantcast