NamedRange.BeforeRightClick 事件

当在默认的右击操作之前右击 NamedRange 控件时发生。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
Event BeforeRightClick As DocEvents_BeforeRightClickEventHandler
event DocEvents_BeforeRightClickEventHandler BeforeRightClick

备注

如果右击重叠的 NamedRange 控件,将对发生重叠的每个控件引发该事件。

示例

下面的代码示例创建一个 NamedRange,然后用文本 Delete 填充所有的单元格。若要测试事件,请右击某个单元格,以便在该范围周围出现一个边框,然后双击某个单元格即可清除该范围。

此版本针对的是文档级自定义项。

Private clickRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub ClickToChangeRange()
    clickRange = Me.Controls.AddNamedRange(Me.Range("B2", "D4"), _
        "clickRange")
    clickRange.Value2 = "Delete"
    AddHandler clickRange.BeforeDoubleClick, _
        AddressOf clickRange_BeforeDoubleClick
    AddHandler clickRange.BeforeRightClick, _
        AddressOf clickRange_BeforeRightClick
End Sub


Sub clickRange_BeforeRightClick(ByVal Target As Excel.Range, _
    ByRef Cancel As Boolean)
    clickRange.BorderAround(, Excel.XlBorderWeight.xlThick, _
        Excel.XlColorIndex.xlColorIndexAutomatic, )
    Cancel = True
End Sub


Sub clickRange_BeforeDoubleClick(ByVal Target As _
    Excel.Range, ByRef Cancel As Boolean)
    clickRange.Clear()
    Cancel = True
End Sub
Microsoft.Office.Tools.Excel.NamedRange clickRange;
private void ClickToChangeRange()
{
    clickRange = this.Controls.AddNamedRange(
        this.Range["B2", "D4"], "clickRange");
    clickRange.Value2 = "Delete";
    clickRange.BeforeDoubleClick += new 
        Microsoft.Office.Interop.Excel.
        DocEvents_BeforeDoubleClickEventHandler(
        clickRange_BeforeDoubleClick);
    clickRange.BeforeRightClick += new 
        Microsoft.Office.Interop.Excel.
        DocEvents_BeforeRightClickEventHandler(
        clickRange_BeforeRightClick);
}

void clickRange_BeforeRightClick(
    Excel.Range Target, ref bool Cancel)
{
    clickRange.BorderAround(missing, Excel.XlBorderWeight.xlThick,
        Excel.XlColorIndex.xlColorIndexAutomatic);
    Cancel = true;
}

void clickRange_BeforeDoubleClick(
    Excel.Range Target, ref bool Cancel)
{
    clickRange.Clear();
    Cancel = true;
}

此版本针对的是应用程序级外接程序。

.NET Framework 安全性

请参见

参考

NamedRange 接口

Microsoft.Office.Tools.Excel 命名空间