Customize the Context Menu


02-04-2010, 3:45 PM
Hi,

I am looking to do what was done in this article (Scroll to the 2nd to last post in the forum which I also pasted below) in Active Reports 6:  http://www.datadynamics.com/forums/108463/ShowPost.aspx

Private Sub arDesigner_ContextMenuOpen(ByVal sender As Object, ByVal e As DataDynamics.ActiveReports.Design.ContextMenuOpenArgs) Handles arDesigner.ContextMenuOpen
        'The user right-clicked a control
        If Me.arDesigner.Selection(0).GetType.BaseType.ToString = "DataDynamics.ActiveReports.ARControl" Then
            If _isContextMenuOpen Then
                _isContextMenuOpen = False
            Else
                'Cancel the normal context menu
                e.Cancel = True
                Dim ctrlContextMenu As CommandBarContextMenu = New CommandBarContextMenu()
     
                'add Cut to context menu
                ctrlContextMenu.Items.Add(commandBarManager.CommandBars.Item(2).Items(0))

                'add Copy to context menu
                ctrlContextMenu.Items.Add(commandBarManager.CommandBars.Item(2).Items(1))

                'add Paste to context menu
                ctrlContextMenu.Items.Add(commandBarManager.CommandBars.Item(2).Items(2))

                'add Delete to context menu
                ctrlContextMenu.Items.Add(commandBarManager.CommandBars.Item(2).Items(3))

                ctrlContextMenu.Items.AddSeparator()

                'add Bring to Front to context menu
                ctrlContextMenu.Items.Add(commandBarManager.CommandBars.Item(6).Items(10))

                'add Send to Back to context menu
                ctrlContextMenu.Items.Add(commandBarManager.CommandBars.Item(6).Items(11))

                ctrlContextMenu.Items.AddSeparator()

                Me.arDesigner.ContextMenu = ctrlContextMenu

                'display the controls' context menu
                Dim x As Integer = Control.MousePosition.X
                Dim y As Integer = Control.MousePosition.Y
                Me.arDesigner.ShowContextMenu(ctrlContextMenu, New Point(x, y))
                _isContextMenuOpen = True
            End If
        End If

    End Sub


Re: Customize the Context Menu


02-08-2010, 2:47 AM
You can use the following code in ActiveReports 6 Designer to customize the context menu:

void arDesigner_ContextMenuOpen(object sender, ContextMenuOpenArgs e)
{
            if (isContextMenuOpen)
                isContextMenuOpen = false;
            else
            {
                e.Cancel = true;

System.Windows.Forms.ContextMenuStrip cntxtMenu = new ContextMenuStrip();                cntxtMenu.Items.Add("Copy");
cntxtMenu.Items.Add("Paset");  
cntxtMenu.Items[0].Click+=new EventHandler(CopyMenu_Click);
cntxtMenu.Items[1].Click+=new EventHandler(PasteMenu_Click);
arDesigner.ContextMenuStrip = cntxtMenu;
arDesigner.ContextMenuStrip.Show(this, new System.Drawing.Point(Control.MousePosition.X, Control.MousePosition.Y));
isContextMenuOpen = true;

            }
 }

 void CopyMenu_Click(object sender, EventArgs e)
 {
     if(arDesigner.QueryActionEnabled(DesignerAction.EditCopy))
            {
               arDesigner.ExecuteAction(DesignerAction.EditCopy);
            }
}

 void PasteMenu_Click(object sender, EventArgs e)
 {
     if(arDesigner.QueryActionEnabled(DesignerAction.EditPaste))
            {
               arDesigner.ExecuteAction(DesignerAction.EditPaste);
            }       
}

Regards,
Ankit Nigam

Re: Customize the Context Menu


09-21-2010, 2:46 AM
Hello,

I need to add some items to the existing context menu. Is it possible to do that without creating my own context menu? If it's not can you please explain how to create my own context menu which looks and behave exactly like the existing context menu?

Thanks,
Silviu

Re: Customize the Context Menu


09-22-2010, 1:33 PM
Hello,

The default ContextMenu is not exposed. Thus that cannot be accessed to add to new items. However you can create a new ContextMenu as Ankit described above and add all the items existed in default ContextMenu and add the desired new items as well. I have attached a sample which demonstrates how to achieve this. Please go through this and let me know if you have further assistance.

Regards,
Subodh