NamedRange.BeforeDoubleClick 事件 (2007 system)

更新: 2008 年 7 月

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

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

语法

声明
Public Event BeforeDoubleClick As DocEvents_BeforeDoubleClickEventHandler
用法
Dim instance As NamedRange
Dim handler As DocEvents_BeforeDoubleClickEventHandler

AddHandler instance.BeforeDoubleClick, handler
public event DocEvents_BeforeDoubleClickEventHandler BeforeDoubleClick

备注

如果双击重叠的 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, missing);
    Cancel = true;
}

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

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

Private clickRange As NamedRange

Private Sub ClickToChangeRange()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    clickRange = vstoWorksheet.Controls.AddNamedRange( _
    vstoWorksheet.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
NamedRange clickRange;
private void ClickToChangeRange()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    clickRange = vstoWorksheet.Controls.AddNamedRange(
        vstoWorksheet.Range["B2", "D4"], "clickRange");
    clickRange.Value2 = "Delete";
    clickRange.BeforeDoubleClick += new
        Excel.DocEvents_BeforeDoubleClickEventHandler(
        clickRange_BeforeDoubleClick);
    clickRange.BeforeRightClick += new
        Excel.DocEvents_BeforeRightClickEventHandler(
        clickRange_BeforeRightClick);
}

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

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

权限

另请参见

参考

NamedRange 类

NamedRange 成员

Microsoft.Office.Tools.Excel 命名空间

修订记录

日期

修订记录

原因

2008 年 7 月

添加了一个针对应用程序级外接程序的代码示例版本。

SP1 功能更改。