Reports for WinForms | ComponentOne
In This Topic
    Removing an Item from the Context Menu
    In This Topic

    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:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      AddHandler PreviewPane.ContextMenuStrip.Opening, AddressOf ContextMenuStrip_Opening
      

      To write code in C#

      C#
      Copy Code
      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:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      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
      

      To write code in C#

      C#
      Copy Code
      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.