WithEvents elementChart As Microsoft.Office.Tools.Excel.Chart
Private Sub DisplayChartElement()
Globals.Sheet1.Range("A1", "A5").Value2 = 22
Globals.Sheet1.Range("B1", "B5").Value2 = 55
elementChart = Me.Controls.AddChart(Me.Range("D2", "H12"), _
"elementChart")
elementChart.SetSourceData(Globals.Sheet1.Range("A1", "B5"), _
Excel.XlRowCol.xlColumns)
elementChart.ChartType = Excel.XlChartType.xl3DColumn
End Sub
Sub elementChart_MouseDownHandler(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal x As Integer, ByVal y As Integer) Handles elementChart.MouseDown
Dim elementID As Integer = 0
Dim arg1 As Integer = 0
Dim arg2 As Integer = 0
Dim innerChart As Excel.Chart = CType( _
Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Unwrap( _
elementChart.InnerObject), Excel.Chart)
innerChart.GetChartElement(x, y, elementID, arg1, arg2)
MsgBox("Chart element is: " & CType(elementID, Excel.XlChartItem).ToString() _
& Constants.vbNewLine & "arg1 is: " & arg1.ToString() _
& Constants.vbNewLine & "arg2 is: " & arg2.ToString())
End Sub
private Microsoft.Office.Tools.Excel.Chart elementChart;
private void DisplayChartElement()
{
this.Range["A1", "A5"].Value2 = 22;
this.Range["B1", "B5"].Value2 = 55;
elementChart = this.Controls.AddChart(this.Range["D2", "H12"],
"elementChart");
elementChart.SetSourceData(this.Range["A1", "B5"],
Excel.XlRowCol.xlColumns);
elementChart.ChartType = Excel.XlChartType.xl3DColumn;
elementChart.MouseDown +=
new Excel.ChartEvents_MouseDownEventHandler(elementChart_MouseDown);
}
void elementChart_MouseDown(int Button, int Shift, int x, int y)
{
Int32 elementID = 0;
Int32 arg1 = 0;
Int32 arg2 = 0;
Excel.Chart innerChart = (Excel.Chart)Microsoft.Office.Tools.
Excel.ExcelLocale1033Proxy.Unwrap(elementChart.InnerObject);
innerChart.GetChartElement(x, y, ref elementID, ref arg1, ref arg2);
MessageBox.Show("Chart element is: " + ((Excel.XlChartItem)elementID).ToString()
+ "\n arg1 is: " + arg1.ToString() + "\n arg2 is: " + arg2.ToString());
}