Udostępnij za pośrednictwem


WorksheetBase.BeforeRightClick Event

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)

Syntax

'Declaration
Public Event BeforeRightClick As DocEvents_BeforeRightClickEventHandler
public event DocEvents_BeforeRightClickEventHandler BeforeRightClick

Examples

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.

Sub Worksheet1_BeforeRightClick(ByVal Target As Excel.Range, _
    ByRef Cancel As Boolean) Handles Me.BeforeRightClick
    MsgBox("Right-clicking in this sheet" & " is not allowed.")
    Cancel = True
End Sub
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;
}

.NET Framework Security

See Also

Reference

WorksheetBase Class

Microsoft.Office.Tools.Excel Namespace