Adding new Menu items seems to work diferently in DRAW X7

Does anybody knows how to use in VB.NET or C# the new features regarding the CommandBars and CommandBar classes in X7 Object Model to add new buttons to the MainMenu 


Thanks,

Parents Reply
  • Jaime, I think what you are asking is possible. You basically need to do two things. First, create a project following the steps in this article.

    Then create a user control with code like this:

    <UserControl x:Class="CoreDrawPoC.Forms.Menu2"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:CoreDrawPoC.Forms">
        <DockPanel HorizontalAlignment="Left">
            <Menu Background="#D8D8D8" >
                <MenuItem Header="_Tools" Click="MenuItem_Click" VerticalAlignment="Center" Padding="5,0,5,1" FontSize="13" FontWeight="DemiBold">
                    <MenuItem.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="_Manage Settings" MenuItem.Click="ManageSettings_Click" >
                                <MenuItem.Icon>
                                    <Image Source="C:\CorelVSTA\Three.bmp" />
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </MenuItem.ContextMenu>
                </MenuItem>
            </Menu>
        </DockPanel>
    </UserControl>
    

    Then modify your code behind like this:

    namespace CoreDrawPoC.Forms
    {
        /// <summary>
        /// Interaction logic for Menu2.xaml
        /// </summary>
        public partial class Menu2 : UserControl
        {
            Corel.Interop.VGCore.Application appDraw = null;
    
            public Menu2()
            {
                InitializeComponent();
            }
    
            public Menu2(object app)
            {
                InitializeComponent();
                appDraw = (Corel.Interop.VGCore.Application)app;
            }
    
            private void ManageSettings_Click(object sender, RoutedEventArgs e)
            {
                var testWindow = new TestWindow();
                testWindow.ShowDialog();
            }
    
            private void MenuItem_Click(object sender, RoutedEventArgs e)
            {
                var menuItem = sender as MenuItem;
                menuItem.ContextMenu.IsEnabled = true;
                menuItem.ContextMenu.PlacementTarget = (sender as MenuItem);
                menuItem.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
                menuItem.ContextMenu.IsOpen = true;
            }
        }
    }
    

    Once that is done, compile the code, drop the .dll's into the folder you will access it from (in my case I put the .dll in C:\CorelVSTA). Note, in my example code, the TestWindow object is just a custom WPF window that pops up and loads data from the database. Once you deploy the dll, add the below code to your VSTA global project and run it onces from the Macro Manager window and the menu will appear.  Let me know if you have questions.

    [CgsAddInMacro]
            public void AddMenu2()
            {
                string controlAssembly = @"C:\CorelVSTA\CoreDrawPoC.dll";
                var newButton = app.FrameWork.MainMenu.Controls.AddCustomControl("CoreDrawPoC.Forms.Menu2", controlAssembly);
                newButton.DescriptionText = "Menu Bar D";
                newButton.Caption = "Menu Bar C";
                newButton.ToolTipText = "Menu Bar T";
            }
    
Children