Form.KeyPreview=Trueのとき、F2キーを検出できない場合があるのはなぜですか?
対象製品
MultiRow for Windows Forms 10.0J
詳細
GcMultiRowコントロールでは、既定でF2キーがセルの編集開始に割り当てられており、GcMultiRowコントロールがこのキーを処理する場合にはForm.KeyPreview=Trueの場合でもF2キーをForm.KeyDownイベントで処理することができません。
F2キーをFormで処理するには、次のようにGcMultiRowコントロールのショートカットキーの割り当てを解除します。
[Visual Basic]
[C#]
同様のキーにF4キーによる編集の開始とドロップダウンウィンドウの表示があります。
F2キーをFormで処理するには、次のようにGcMultiRowコントロールのショートカットキーの割り当てを解除します。
[Visual Basic]
Imports GrapeCity.Win.MultiRow Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.KeyPreview = True GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {New TextBoxCell()}) GcMultiRow1.ShortcutKeyManager.Unregister(Keys.F2) End Sub Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.F2 Then If TypeOf Me.ActiveControl Is GcMultiRow Then Console.WriteLine("F2 key down") ' F2キーによる編集の開始が必要な場合 EditingActions.BeginEdit.Execute(TryCast(Me.ActiveControl, GcMultiRow)) End If e.Handled = True End If End Sub
[C#]
using GrapeCity.Win.MultiRow; private void Form1_Load(object sender, EventArgs e) { this.KeyPreview = true; this.KeyDown += new KeyEventHandler(Form1_KeyDown); this.gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { new TextBoxCell() }); this.gcMultiRow1.ShortcutKeyManager.Unregister(Keys.F2); } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F2) { if (this.ActiveControl is GcMultiRow) { Console.WriteLine("F2 key down"); // F2キーによる編集の開始が必要な場合 // EditingActions.BeginEdit.Execute(this.ActiveControl as GcMultiRow); } e.Handled = true; } }
同様のキーにF4キーによる編集の開始とドロップダウンウィンドウの表示があります。