MESCIUS SPREAD for Windows Forms 17.0J サンプルコード集
指定した座標からセルのインデックスを取得する
MESCIUS SPREAD for Windows Forms 17.0J サンプルコード集 > 操作 > セル > 指定した座標からセルのインデックスを取得する

SheetViewクラスのGetCellReferenceメソッドにx位置とy位置を引数として渡すことでセルのリファレンスを取得できます。例えば、シート上に配置された画像オブジェクトが、どのセル範囲に配置されているかを取得することが可能です。

【実行例】

コンテキストメニュー

 private void Form1_Load(object sender, EventArgs e)
 {
  FarPoint.Win.Spread.DrawingSpace.RectangleShape s = new FarPoint.Win.Spread.DrawingSpace.RectangleShape();
  s.Size = new System.Drawing.Size(100, 100);
  fpSpread1.ActiveSheet.AddShape(s, 1, 1);

  // GetCellReferenceメソッドの呼び出し
  Console.WriteLine("シェイプの左上のセルインデックス:" + fpSpread1.ActiveSheet.GetCellReference(s.Location.X, s.Location.Y).ToString());
  Console.WriteLine("シェイプの右下のセルインデックス:" + fpSpread1.ActiveSheet.GetCellReference(s.Location.X + s.Size.Width, s.Location.Y + s.Size.Height).ToString());
 }
 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  Dim s As New FarPoint.Win.Spread.DrawingSpace.RectangleShape()
  s.Size = New System.Drawing.Size(100, 100)
  FpSpread1.ActiveSheet.AddShape(s, 1, 1)

  ' GetCellReferenceメソッドの呼び出し
  Console.WriteLine("シェイプの左上のセルインデックス:" + FpSpread1.ActiveSheet.GetCellReference(s.Location.X, s.Location.Y).ToString())
  Console.WriteLine("シェイプの右下のセルインデックス:" + FpSpread1.ActiveSheet.GetCellReference(s.Location.X + s.Size.Width, s.Location.Y + s.Size.Height).ToString())
 End Sub