ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Printing and Previewing Task-Based Help > Formatting Tables > Removing an Item from the Context Menu

Removing an Item from the Context Menu

By default a context menu appears when the C1PreviewPane is right-clicked at run time. This ContextMenuStrip includes settings for manipulating the preview including items from the File, Zoom, and Text toobars. You can create your own context menu by adding a ContextMenuStrip control and assigning it to the PreviewPane.ContextMenuStrip property. You can also customize the existing ContextMenuStrip by adding additional items or removing existing items.

The following example removes the standard "Copy" item from the context menu. Complete the following steps:

1.   In the Form_Load event attach a handler to the Opening event of the ContextMenuStrip on the C1PreviewPane:

      Visual Basic

AddHandler PreviewPane.ContextMenuStrip.Opening, AddressOf ContextMenuStrip_Opening

      C#

PreviewPane.ContextMenuStrip.Opening += new CancelEventHandler(ContextMenuStrip_Opening);

2.   Create the ContextMenuStrip_Opening event, and add the following code to remove the "Copy" item from the context menu:

      Visual Basic

Private Sub ContextMenuStrip_Opening(ByVal sender As Object, ByVal e As CancelEventArgs)

    Dim cms As System.Windows.Forms.ContextMenuStrip = DirectCast(sender, System.Windows.Forms.ContextMenuStrip)

    For Each item As ToolStripItem In cms.Items

        If item.Tag = ContextMenuTags.Copy Then

            item.Visible = False

        End If

    Next

End Sub

      C#

void ContextMenuStrip_Opening(object sender, CancelEventArgs e)

{

  System.Windows.Forms.ContextMenuStrip cms = (System.Windows.Forms.ContextMenuStrip)sender;

  foreach (ToolStripItem item in cms.Items)

    if (item.Tag == ContextMenuTags.Copy)

      item.Visible = false;

}

 What You've Accomplished

When you right-click the preview pane in the C1PrintPreviewControl control, observe that the standard "Copy" item is not included on the context menu.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.