Chart.BeforeDoubleClick 事件

在双击 Chart 控件时,但在默认双击操作之前发生。

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

语法

声明
Event BeforeDoubleClick As ChartEvents_BeforeDoubleClickEventHandler
event ChartEvents_BeforeDoubleClickEventHandler BeforeDoubleClick

备注

DoubleClick 方法不会导致此事件发生。

示例

下面的代码示例创建一个具有 BeforeDoubleClick 事件的处理函数的 Chart,该处理函数在双击图表的轴时显示一个消息框。 该示例还将事件处理程序的 Cancel 参数设置为 true,以便在用户双击轴时图表不接收双击操作。

WithEvents DoubleClickChart As Microsoft.Office.Tools.Excel.Chart

Private Sub DisallowDoubleClicksOnAxis()
    Me.Range("A1", "A5").Value2 = 22
    Me.Range("B1", "B5").Value2 = 55

    DoubleClickChart = Me.Controls.AddChart(Me.Range("D2", "H12"), _
        "DoubleClickChart")
    DoubleClickChart.SetSourceData(Me.Range("A1", "B5"), _
        Excel.XlRowCol.xlColumns)
    DoubleClickChart.ChartType = Excel.XlChartType.xl3DColumn
End Sub

Sub DoubleClickChart_BeforeDoubleClick(ByVal ElementID As Integer, _
    ByVal Arg1 As Integer, ByVal Arg2 As Integer, _
    ByRef Cancel As Boolean) Handles DoubleClickChart.BeforeDoubleClick

    If ElementID = Fix(Excel.XlChartItem.xlAxis) Then
        MsgBox("Formatting this axis is not allowed.")
        Cancel = True
    End If
End Sub
private void DisallowDoubleClicksOnAxis()
{
    this.Range["A1", "A5"].Value2 = 22;
    this.Range["B1", "B5"].Value2 = 55;

    Microsoft.Office.Tools.Excel.Chart chart1 =
        this.Controls.AddChart(this.Range["D2", "H12"], 
        "chart1");
    chart1.SetSourceData(this.Range["A1", "B5"], 
        Excel.XlRowCol.xlColumns);
    chart1.ChartType = Excel.XlChartType.xl3DColumn;

    chart1.BeforeDoubleClick +=
        new Excel.ChartEvents_BeforeDoubleClickEventHandler(
        chart1_BeforeDoubleClick);
}

void chart1_BeforeDoubleClick(int ElementID, int Arg1, 
    int Arg2, ref bool Cancel)
{
    if (ElementID == (int)Excel.XlChartItem.xlAxis)
    {
        MessageBox.Show("Formatting this axis is not allowed.");
        Cancel = true;
    }
}

.NET Framework 安全性

请参见

参考

Chart 接口

Microsoft.Office.Tools.Excel 命名空间