セル編集開始時のカーソル位置を変更したい
対象製品
SPREAD for Windows Forms 7.0J
詳細
SPREAD for Windows Forms 5Jから追加されたFocusPositionプロパティにより、
セルが編集状態になった時のカーソル位置を変更することが可能になりました。
EditorFocusCursorPosition列挙体により、フォーカス位置の指定方法を下記5種類の中から選択することができます。
◎サンプルコード(VB)
◎サンプルコード(C#)
セルが編集状態になった時のカーソル位置を変更することが可能になりました。
EditorFocusCursorPosition列挙体により、フォーカス位置の指定方法を下記5種類の中から選択することができます。
◎サンプルコード(VB)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' エディタのタイプまたは選択ポリシーによって決定(デフォルト)
Dim txt_Inherit As New FarPoint.Win.Spread.CellType.TextCellType
txt_Inherit.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.Inherit
FpSpread1.Sheets(0).Cells(0, 0).CellType = txt_Inherit
' クリックした位置にカーソルを配置(Excelと同様の動作)
Dim txt_MouseLocation As New FarPoint.Win.Spread.CellType.TextCellType
txt_MouseLocation.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.MouseLocation
FpSpread1.Sheets(0).Cells(0, 1).CellType = txt_MouseLocation
' 常に先頭にカーソルを配置
Dim txt_FirstInputPosition As New FarPoint.Win.Spread.CellType.TextCellType
txt_FirstInputPosition.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.FirstInputPosition
FpSpread1.Sheets(0).Cells(0, 2).CellType = txt_FirstInputPosition
' 常に最後方にカーソルを配置
Dim txt_End As New FarPoint.Win.Spread.CellType.TextCellType
txt_End.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.End
FpSpread1.Sheets(0).Cells(0, 3).CellType = txt_End
' 文字列を全選択状態にする
Dim txt_SelectAll As New FarPoint.Win.Spread.CellType.TextCellType
txt_SelectAll.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.SelectAll
FpSpread1.Sheets(0).Cells(0, 4).CellType = txt_SelectAll
FpSpread1.Sheets(0).SetValue(0, 0, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 1, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 2, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 3, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 4, "1234567890")
End Sub
' エディタのタイプまたは選択ポリシーによって決定(デフォルト)
Dim txt_Inherit As New FarPoint.Win.Spread.CellType.TextCellType
txt_Inherit.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.Inherit
FpSpread1.Sheets(0).Cells(0, 0).CellType = txt_Inherit
' クリックした位置にカーソルを配置(Excelと同様の動作)
Dim txt_MouseLocation As New FarPoint.Win.Spread.CellType.TextCellType
txt_MouseLocation.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.MouseLocation
FpSpread1.Sheets(0).Cells(0, 1).CellType = txt_MouseLocation
' 常に先頭にカーソルを配置
Dim txt_FirstInputPosition As New FarPoint.Win.Spread.CellType.TextCellType
txt_FirstInputPosition.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.FirstInputPosition
FpSpread1.Sheets(0).Cells(0, 2).CellType = txt_FirstInputPosition
' 常に最後方にカーソルを配置
Dim txt_End As New FarPoint.Win.Spread.CellType.TextCellType
txt_End.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.End
FpSpread1.Sheets(0).Cells(0, 3).CellType = txt_End
' 文字列を全選択状態にする
Dim txt_SelectAll As New FarPoint.Win.Spread.CellType.TextCellType
txt_SelectAll.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.SelectAll
FpSpread1.Sheets(0).Cells(0, 4).CellType = txt_SelectAll
FpSpread1.Sheets(0).SetValue(0, 0, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 1, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 2, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 3, "1234567890")
FpSpread1.Sheets(0).SetValue(0, 4, "1234567890")
End Sub
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
// エディタのタイプまたは選択ポリシーによって決定(デフォルト)
FarPoint.Win.Spread.CellType.TextCellType txt_Inherit = new FarPoint.Win.Spread.CellType.TextCellType();
txt_Inherit.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.Inherit;
fpSpread1.Sheets[0].Cells[0, 0].CellType = txt_Inherit;
// クリックした位置にカーソルを配置(Excelと同様の動作)
FarPoint.Win.Spread.CellType.TextCellType txt_MouseLocation = new FarPoint.Win.Spread.CellType.TextCellType();
txt_MouseLocation.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.MouseLocation;
fpSpread1.Sheets[0].Cells[0, 1].CellType = txt_MouseLocation;
// 常に先頭にカーソルを配置
FarPoint.Win.Spread.CellType.TextCellType txt_FirstInputPosition = new FarPoint.Win.Spread.CellType.TextCellType();
txt_FirstInputPosition.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.FirstInputPosition;
fpSpread1.Sheets[0].Cells[0, 2].CellType = txt_FirstInputPosition;
// 常に最後方にカーソルを配置
FarPoint.Win.Spread.CellType.TextCellType txt_End = new FarPoint.Win.Spread.CellType.TextCellType();
txt_End.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.End;
fpSpread1.Sheets[0].Cells[0, 3].CellType = txt_End;
// 文字列を全選択状態にする
FarPoint.Win.Spread.CellType.TextCellType txt_SelectAll = new FarPoint.Win.Spread.CellType.TextCellType();
txt_SelectAll.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.SelectAll;
fpSpread1.Sheets[0].Cells[0, 4].CellType = txt_SelectAll;
fpSpread1.Sheets[0].SetValue(0, 0, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 1, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 2, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 3, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 4, "1234567890");
}
{
// エディタのタイプまたは選択ポリシーによって決定(デフォルト)
FarPoint.Win.Spread.CellType.TextCellType txt_Inherit = new FarPoint.Win.Spread.CellType.TextCellType();
txt_Inherit.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.Inherit;
fpSpread1.Sheets[0].Cells[0, 0].CellType = txt_Inherit;
// クリックした位置にカーソルを配置(Excelと同様の動作)
FarPoint.Win.Spread.CellType.TextCellType txt_MouseLocation = new FarPoint.Win.Spread.CellType.TextCellType();
txt_MouseLocation.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.MouseLocation;
fpSpread1.Sheets[0].Cells[0, 1].CellType = txt_MouseLocation;
// 常に先頭にカーソルを配置
FarPoint.Win.Spread.CellType.TextCellType txt_FirstInputPosition = new FarPoint.Win.Spread.CellType.TextCellType();
txt_FirstInputPosition.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.FirstInputPosition;
fpSpread1.Sheets[0].Cells[0, 2].CellType = txt_FirstInputPosition;
// 常に最後方にカーソルを配置
FarPoint.Win.Spread.CellType.TextCellType txt_End = new FarPoint.Win.Spread.CellType.TextCellType();
txt_End.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.End;
fpSpread1.Sheets[0].Cells[0, 3].CellType = txt_End;
// 文字列を全選択状態にする
FarPoint.Win.Spread.CellType.TextCellType txt_SelectAll = new FarPoint.Win.Spread.CellType.TextCellType();
txt_SelectAll.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.SelectAll;
fpSpread1.Sheets[0].Cells[0, 4].CellType = txt_SelectAll;
fpSpread1.Sheets[0].SetValue(0, 0, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 1, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 2, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 3, "1234567890");
fpSpread1.Sheets[0].SetValue(0, 4, "1234567890");
}
関連情報
- 【セル型全般】 編集中セルにてEnterキー押下によるKeyイベントを取得する方法
- 【セル型全般】 編集中のセルでKeyイベントが発生しません
- 【セル型全般】 カスタムサブエディタの表示位置を変更したい
- 【セル型全般】 編集中セルの文字色/背景色を変更する方法
- セルの編集用コントロールを取得するには
キーワード
「編集用コントロール」