次の方法で共有


WorksheetBase.BeforeRightClick Event

Definition

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

public:
 event Microsoft::Office::Interop::Excel::DocEvents_BeforeRightClickEventHandler ^ BeforeRightClick;
public event Microsoft.Office.Interop.Excel.DocEvents_BeforeRightClickEventHandler BeforeRightClick;
member this.BeforeRightClick : Microsoft.Office.Interop.Excel.DocEvents_BeforeRightClickEventHandler 
Public Custom Event BeforeRightClick As DocEvents_BeforeRightClickEventHandler 

Event Type

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.

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;
}
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

Applies to