Export (0) Print
Expand All

WorksheetBase.BeforeRightClick Event

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Occurs when the worksheet is right-clicked, before the default right-click action.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

public event DocEvents_BeforeRightClickEventHandler BeforeRightClick

The following code example demonstrates a handler for the BeforeRightClick event that cancels the right-click action on the current worksheet. The event handler informs the user that right-clicking is not allowed for the worksheet, and then sets the Cancel parameter of the DocEvents_BeforeRightClickEventHandler event handler to true so that Microsoft Office Excel cancels the right-click action.

This example is for a document-level customization.

private void WorksheetBeforeRightClick()
{
    this.BeforeRightClick += 
        new Excel.DocEvents_BeforeRightClickEventHandler(
        Worksheet1_BeforeRightClick);
}

void Worksheet1_BeforeRightClick(Excel.Range Target, 
    ref bool Cancel)
{
    MessageBox.Show("Right-clicking in this sheet" +
        " is not allowed.");
    Cancel = true;
}

Show:
© 2014 Microsoft