Evento NamedRange.BeforeRightClick

Ocorre quando um NamedRange controle é right-clicked, antes do padrão de atalho ação.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (em Microsoft.Office.Tools.Excel.dll)

Sintaxe

'Declaração
Event BeforeRightClick As DocEvents_BeforeRightClickEventHandler
event DocEvents_BeforeRightClickEventHandler BeforeRightClick

Comentários

Clicando em sobreposição NamedRange controles dispara o evento em cada um dos controles que se sobrepõem.

Exemplos

O exemplo de código a seguir cria um NamedRange e, em seguida, preenche todas as células com o texto Excluir. Para testar os eventos, clique em uma das células para tornar uma borda aparecem ao redor do intervalo e, em seguida, clique duas vezes em uma das células para limpar o intervalo.

Esta versão é para uma personalização em nível de documento.

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

Esta versão é um suplemento em nível de aplicativo.

Private clickRange As NamedRange

Private Sub ClickToChangeRange()

    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
        Globals.ThisAddIn.Application.ActiveSheet

    Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
            Globals.Factory.GetVstoObject(NativeWorksheet)

    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 =
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    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;
}

Segurança do .NET Framework

Consulte também

Referência

NamedRange Interface

Namespace Microsoft.Office.Tools.Excel