MESCIUS SPREAD for Windows Forms 15.0J サンプルコード集 > チャート > 選択されたタイミングを取得する(チャート全体) |
シート上のチャートオブジェクトを選択した場合にはShapeActicatedイベントが発生するため、FpSpreadクラスのActiveWindowlessObjectプロパティとの併用により、現在選択されているオブジェクトの属性を取得することができます。
なお、現在選択されているチャートやシェイプが存在しない場合、ActiveWindowlessObjectプロパティの値はNothing(C#ではnull)となります。
チャートが選択されました |
チャートが選択されました |
private void Form1_Load(object sender, System.EventArgs e) { // データを設定します fpSpread1.Sheets[0].Cells[0, 1].Value = "L1"; fpSpread1.Sheets[0].Cells[0, 2].Value = "L2"; fpSpread1.Sheets[0].Cells[0, 3].Value = "L3"; fpSpread1.Sheets[0].Cells[1, 0].Value = "1Q"; fpSpread1.Sheets[0].Cells[2, 0].Value = "2Q"; fpSpread1.Sheets[0].Cells[3, 0].Value = "3Q"; fpSpread1.Sheets[0].Cells[4, 0].Value = "4Q"; fpSpread1.Sheets[0].Cells[1, 1].Value = 50; fpSpread1.Sheets[0].Cells[2, 1].Value = 30; fpSpread1.Sheets[0].Cells[3, 1].Value = 20; fpSpread1.Sheets[0].Cells[4, 1].Value = 40; fpSpread1.Sheets[0].Cells[1, 2].Value = 30; fpSpread1.Sheets[0].Cells[2, 2].Value = 15; fpSpread1.Sheets[0].Cells[3, 2].Value = 50; fpSpread1.Sheets[0].Cells[4, 2].Value = 20; fpSpread1.Sheets[0].Cells[1, 3].Value = 10; fpSpread1.Sheets[0].Cells[2, 3].Value = 40; fpSpread1.Sheets[0].Cells[3, 3].Value = 25; fpSpread1.Sheets[0].Cells[4, 3].Value = 25; fpSpread1.Sheets[0].Cells[0, 6].Value = "B1"; fpSpread1.Sheets[0].Cells[0, 7].Value = "B2"; fpSpread1.Sheets[0].Cells[0, 8].Value = "B3"; fpSpread1.Sheets[0].Cells[1, 5].Value = "1Q"; fpSpread1.Sheets[0].Cells[2, 5].Value = "2Q"; fpSpread1.Sheets[0].Cells[3, 5].Value = "3Q"; fpSpread1.Sheets[0].Cells[4, 5].Value = "4Q"; fpSpread1.Sheets[0].Cells[1, 6].Value = 1050; fpSpread1.Sheets[0].Cells[2, 6].Value = 1500; fpSpread1.Sheets[0].Cells[3, 6].Value = 2300; fpSpread1.Sheets[0].Cells[4, 6].Value = 3500; fpSpread1.Sheets[0].Cells[1, 7].Value = 3000; fpSpread1.Sheets[0].Cells[2, 7].Value = 2500; fpSpread1.Sheets[0].Cells[3, 7].Value = 3200; fpSpread1.Sheets[0].Cells[4, 7].Value = 3300; fpSpread1.Sheets[0].Cells[1, 8].Value = 4000; fpSpread1.Sheets[0].Cells[2, 8].Value = 1500; fpSpread1.Sheets[0].Cells[3, 8].Value = 2000; fpSpread1.Sheets[0].Cells[4, 8].Value = 2300; // データ領域およスタイルを指定してチャートを設定します FarPoint.Win.Spread.Model.CellRange rangeline = new FarPoint.Win.Spread.Model.CellRange(0, 0, 5, 4); fpSpread1.Sheets[0].AddChart(rangeline, typeof(FarPoint.Win.Chart.LineSeries), 250, 200, 5, 120, FarPoint.Win.Chart.ChartViewType.View2D, true); // データ領域およスタイルを指定してチャートを設定します FarPoint.Win.Spread.Model.CellRange rangebar = new FarPoint.Win.Spread.Model.CellRange(0, 5, 5, 4); fpSpread1.Sheets[0].AddChart(rangebar, typeof(FarPoint.Win.Chart.ClusteredBarSeries), 250, 200, 270, 120, FarPoint.Win.Chart.ChartViewType.View2D, true); } private void fpSpread1_ShapeActivated(object sender, EventArgs e) { if (((FarPoint.Win.Spread.FpSpread)sender).ActiveWindowlessObject is FarPoint.Win.Spread.Chart.SpreadChart) { // チャートオブジェクト取得します FarPoint.Win.Spread.Chart.SpreadChart spreadChart = (FarPoint.Win.Spread.Chart.SpreadChart)((FarPoint.Win.Spread.FpSpread)sender).ActiveWindowlessObject; if (spreadChart != null) { Console.WriteLine("チャートが選択されました"); Console.WriteLine("選択されたチャートは:" + spreadChart.Model.PlotAreas[0].Series[0].ToString() + "です"); } } }
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ' データを設定します FpSpread1.Sheets(0).Cells(0, 1).Value = "L1" FpSpread1.Sheets(0).Cells(0, 2).Value = "L2" FpSpread1.Sheets(0).Cells(0, 3).Value = "L3" FpSpread1.Sheets(0).Cells(1, 0).Value = "1Q" FpSpread1.Sheets(0).Cells(2, 0).Value = "2Q" FpSpread1.Sheets(0).Cells(3, 0).Value = "3Q" FpSpread1.Sheets(0).Cells(4, 0).Value = "4Q" FpSpread1.Sheets(0).Cells(1, 1).Value = 50 FpSpread1.Sheets(0).Cells(2, 1).Value = 30 FpSpread1.Sheets(0).Cells(3, 1).Value = 20 FpSpread1.Sheets(0).Cells(4, 1).Value = 40 FpSpread1.Sheets(0).Cells(1, 2).Value = 30 FpSpread1.Sheets(0).Cells(2, 2).Value = 15 FpSpread1.Sheets(0).Cells(3, 2).Value = 50 FpSpread1.Sheets(0).Cells(4, 2).Value = 20 FpSpread1.Sheets(0).Cells(1, 3).Value = 10 FpSpread1.Sheets(0).Cells(2, 3).Value = 40 FpSpread1.Sheets(0).Cells(3, 3).Value = 25 FpSpread1.Sheets(0).Cells(4, 3).Value = 25 FpSpread1.Sheets(0).Cells(0, 6).Value = "B1" FpSpread1.Sheets(0).Cells(0, 7).Value = "B2" FpSpread1.Sheets(0).Cells(0, 8).Value = "B3" FpSpread1.Sheets(0).Cells(1, 5).Value = "1Q" FpSpread1.Sheets(0).Cells(2, 5).Value = "2Q" FpSpread1.Sheets(0).Cells(3, 5).Value = "3Q" FpSpread1.Sheets(0).Cells(4, 5).Value = "4Q" FpSpread1.Sheets(0).Cells(1, 6).Value = 1050 FpSpread1.Sheets(0).Cells(2, 6).Value = 1500 FpSpread1.Sheets(0).Cells(3, 6).Value = 2300 FpSpread1.Sheets(0).Cells(4, 6).Value = 3500 FpSpread1.Sheets(0).Cells(1, 7).Value = 3000 FpSpread1.Sheets(0).Cells(2, 7).Value = 2500 FpSpread1.Sheets(0).Cells(3, 7).Value = 3200 FpSpread1.Sheets(0).Cells(4, 7).Value = 3300 FpSpread1.Sheets(0).Cells(1, 8).Value = 4000 FpSpread1.Sheets(0).Cells(2, 8).Value = 1500 FpSpread1.Sheets(0).Cells(3, 8).Value = 2000 FpSpread1.Sheets(0).Cells(4, 8).Value = 2300 ' データ領域およスタイルを指定してチャートを設定します Dim rangeline As New FarPoint.Win.Spread.Model.CellRange(0, 0, 5, 4) FpSpread1.Sheets(0).AddChart(rangeline, GetType(FarPoint.Win.Chart.LineSeries), 250, 200, 5, 120, FarPoint.Win.Chart.ChartViewType.View2D, True) ' データ領域およスタイルを指定してチャートを設定します Dim rangebar As New FarPoint.Win.Spread.Model.CellRange(0, 5, 5, 4) FpSpread1.Sheets(0).AddChart(rangebar, GetType(FarPoint.Win.Chart.ClusteredBarSeries), 250, 200, 270, 120, FarPoint.Win.Chart.ChartViewType.View2D, True) End Sub Private Sub FpSpread1_ShapeActivated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FpSpread1.ShapeActivated If TypeOf (CType(sender, FarPoint.Win.Spread.FpSpread).ActiveWindowlessObject) Is FarPoint.Win.Spread.Chart.SpreadChart Then ' チャートオブジェクト取得します Dim spreadChart As FarPoint.Win.Spread.Chart.SpreadChart = CType(CType(sender, FarPoint.Win.Spread.FpSpread).ActiveWindowlessObject, FarPoint.Win.Spread.Chart.SpreadChart) If Not spreadChart Is Nothing Then Console.WriteLine("チャートが選択されました") Console.WriteLine("選択されたチャートは:" + spreadChart.Model.PlotAreas(0).Series(0).ToString() + "です") End If End If End Sub