I've seen several posts throughout the forums where people have had issues using more than one CommandBars object in the same application. Two very common scenarios for using multiple CommandBars objects are:
- One CommandBars object on an MDI form and another for each MDI Child Form
- One CommandBars object for the main form and another CommandBars object for a DockingPane docked to the main form
The main reason for using mutiple CommandBars objects is that the CommandBars object can only control toolbars on the form it is contained within (I believe this is an ActiveX limitation only, but I could be wrong). That's the reason that MDI Child forms and DockingPanes have to have their own CommandBars object.
A well-noted issue is that the KeyBindings are only executed for the main CommandBars object. Any KeyBindings on other forms are ignored.
Another big issue seems to be with Customizing toolbars. The ablity to customize toolbars and menus was a big selling point for the CommandBars control. This ablity to customize, however, becomes a nightmare when the same control needs to be displayed on more than one CommandBars object (i.e. have 'Cut' in the 'Edit' menu of the main form but also as a toolbar control on a DockingPane). Even though the two controls have the same ID, any customization made the control on the main CommandBars menu is not replicated to the same control on the DockingPane. This means that Captions, Images, KeyBindings, etc are now "out of sync". Without the ablity to keep the items in sync, it's not feasible to allow customization when you also need to have multiple CommandBars objects.
So what's the solution? I don't know. I'm hoping Codejock has the answer.
A solution to the Customization problem could possibly be resolved in two ways.
- Have a Global object for all CommandBars in the application that is used to automatically syncronize controls of the same ID between multiple CommandBar objects when any of those controls are changed.
- Expose an event for when any aspect of a Control is customized. This would allow the developer to propogate that change to the other CommandBar controls.
A possible solution for the KeyBindings problem might be:
- When an accelerator key is pressed, determine which form has focus. If a KeyBinding exists for the CommandBar on that form, issue the Execute event. Otherwise, send the accelerator to the parent of that form.
- Exponse an event for when a KeyBinding is activated that gets called BEFORE the Execute event. Give the developer the ability to reject the accelerator and prevent the Execute event from being fired. The developer can then route the accelerator appropriately to a different CommandBars object. In this scenario, it would also be useful to be able to determine which controls use a particular KeyBinding (I don't currently know of a method).
If anyone else has noticed problems using the more than one CommandBars object in the same project, please post them here. Hopefully Codejock will be able to provide some feedback with workarounds or implement a solution in a future build of the controls.
Of course, the best solution would be to have a single CommandBars object that allows you to create a CommandBar on ANY form (including the ability to dock/undock toolbars between multiple forms) .
I look forward to your feedback.
|