日付時刻コントロールのFieldsEditModeプロパティをUnfixedに設定すると、フィールド間のキャレット移動ができない場合がある
対象製品
InputMan for Windows Forms 7.0J
状況
修正済み
詳細
FieldsEditModeプロパティをUnfixedに設定した日付時刻コントロールで、ショートカットキーやTabキーでキャレットが次/前のフィールドへ移動するように設定しても、移動先のフィールドが未入力の場合は、キャレットが次/前のコントロールに移動してしまいます。
なお、この現象は日付および時刻コントロールでも発生します。
なお、この現象は日付および時刻コントロールでも発生します。
回避方法
この問題はService Pack 3(v7.0.2016.0428)で修正されました。
不具合を修正した最新のサービスパックは、アップデートページ からダウンロードできます。
Service Pack 3より前のバージョンでは次の方法で回避可能です。
次のようにKeyExitイベントを実装します。
[Visual Basic]
Imports GrapeCity.Win.Editors
Imports GrapeCity.Win.Editors.Fields
Private Sub GcDate1_KeyExit(sender As Object, e As KeyExitEventArgs) Handles GcDate1.KeyExit
Dim gcDate As GcDate = sender
If e.Key = ExitKeys.NextControl Or e.Key = ExitKeys.Tab Then
Dim field = gcDate.Fields.FindLast(Function(f As DateField) TypeOf f Is DateInputField)
If Not gcDate.ActiveField Is field And Not gcDate.ActiveField Is gcDate.Fields(gcDate.Fields.Count - 1) Then
gcDate.Focus()
For i As Integer = 0 To gcDate.Fields.Count - 3
If (gcDate.Fields(i) Is gcDate.ActiveField) Then
Dim pos As Integer = 0
For j As Integer = 0 To i + 1
pos = pos + gcDate.Fields(j).Text.Length
Next
gcDate.SelectionStart = pos
Exit For
End If
Next
End If
ElseIf e.Key = ExitKeys.PreviousControl Or e.Key = ExitKeys.ShiftTab Then
Dim field = gcDate.Fields.Find(Function(f As DateField) TypeOf f Is DateInputField)
If Not gcDate.ActiveField Is field And Not gcDate.ActiveField Is gcDate.Fields(0) Then
gcDate.Focus()
For i As Integer = gcDate.Fields.Count - 1 To 1 Step -1
If gcDate.Fields(i) Is gcDate.ActiveField Then
Dim pos As Integer = gcDate.Text.Length
For j As Integer = gcDate.Fields.Count - 1 To i - 1 Step -1
pos -= gcDate.Fields(j).Text.Length
Next
gcDate.SelectionStart = pos
Exit For
End If
Next
End If
End If
End Sub
[C#]
using GrapeCity.Win.Editors;
using GrapeCity.Win.Editors.Fields;
private void gcDate1_KeyExit(object sender, KeyExitEventArgs e)
{
GrapeCity.Win.Editors.GcDate date = sender as GrapeCity.Win.Editors.GcDate;
// 次のフィールドへ移動する場合
if (e.Key == ExitKeys.Tab || e.Key == ExitKeys.NextControl)
{
var field = date.Fields.FindLast((DateField f) => f is DateInputField);
if (date.ActiveField != field && date.ActiveField != date.Fields[date.Fields.Count - 1])
{
date.Focus();
for (int i = 0; i < date.Fields.Count - 2; i++)
{
if (date.Fields[i] == date.ActiveField)
{
int pos = 0;
for (int j = 0; j <= i + 1; j++)
{
pos += date.Fields[j].Text.Length;
}
date.SelectionStart = pos;
break;
}
}
}
}
else if (e.Key == ExitKeys.ShiftTab || e.Key == ExitKeys.PreviousControl)
{
var field = date.Fields.Find((DateField f) => f is DateInputField);
if (date.ActiveField != field && date.ActiveField != date.Fields[0])
{
date.Focus();
for (int i = date.Fields.Count - 1; i > 1; i--)
{
if (date.Fields[i] == date.ActiveField)
{
int pos = date.Text.Length;
for (int j = date.Fields.Count - 1; j >= i - 1; j--)
{
pos -= date.Fields[j].Text.Length;
}
date.SelectionStart = pos;
break;
}
}
}
}
}
不具合を修正した最新のサービスパックは、アップデートページ からダウンロードできます。
Service Pack 3より前のバージョンでは次の方法で回避可能です。
次のようにKeyExitイベントを実装します。
[Visual Basic]
Imports GrapeCity.Win.Editors
Imports GrapeCity.Win.Editors.Fields
Private Sub GcDate1_KeyExit(sender As Object, e As KeyExitEventArgs) Handles GcDate1.KeyExit
Dim gcDate As GcDate = sender
If e.Key = ExitKeys.NextControl Or e.Key = ExitKeys.Tab Then
Dim field = gcDate.Fields.FindLast(Function(f As DateField) TypeOf f Is DateInputField)
If Not gcDate.ActiveField Is field And Not gcDate.ActiveField Is gcDate.Fields(gcDate.Fields.Count - 1) Then
gcDate.Focus()
For i As Integer = 0 To gcDate.Fields.Count - 3
If (gcDate.Fields(i) Is gcDate.ActiveField) Then
Dim pos As Integer = 0
For j As Integer = 0 To i + 1
pos = pos + gcDate.Fields(j).Text.Length
Next
gcDate.SelectionStart = pos
Exit For
End If
Next
End If
ElseIf e.Key = ExitKeys.PreviousControl Or e.Key = ExitKeys.ShiftTab Then
Dim field = gcDate.Fields.Find(Function(f As DateField) TypeOf f Is DateInputField)
If Not gcDate.ActiveField Is field And Not gcDate.ActiveField Is gcDate.Fields(0) Then
gcDate.Focus()
For i As Integer = gcDate.Fields.Count - 1 To 1 Step -1
If gcDate.Fields(i) Is gcDate.ActiveField Then
Dim pos As Integer = gcDate.Text.Length
For j As Integer = gcDate.Fields.Count - 1 To i - 1 Step -1
pos -= gcDate.Fields(j).Text.Length
Next
gcDate.SelectionStart = pos
Exit For
End If
Next
End If
End If
End Sub
[C#]
using GrapeCity.Win.Editors;
using GrapeCity.Win.Editors.Fields;
private void gcDate1_KeyExit(object sender, KeyExitEventArgs e)
{
GrapeCity.Win.Editors.GcDate date = sender as GrapeCity.Win.Editors.GcDate;
// 次のフィールドへ移動する場合
if (e.Key == ExitKeys.Tab || e.Key == ExitKeys.NextControl)
{
var field = date.Fields.FindLast((DateField f) => f is DateInputField);
if (date.ActiveField != field && date.ActiveField != date.Fields[date.Fields.Count - 1])
{
date.Focus();
for (int i = 0; i < date.Fields.Count - 2; i++)
{
if (date.Fields[i] == date.ActiveField)
{
int pos = 0;
for (int j = 0; j <= i + 1; j++)
{
pos += date.Fields[j].Text.Length;
}
date.SelectionStart = pos;
break;
}
}
}
}
else if (e.Key == ExitKeys.ShiftTab || e.Key == ExitKeys.PreviousControl)
{
var field = date.Fields.Find((DateField f) => f is DateInputField);
if (date.ActiveField != field && date.ActiveField != date.Fields[0])
{
date.Focus();
for (int i = date.Fields.Count - 1; i > 1; i--)
{
if (date.Fields[i] == date.ActiveField)
{
int pos = date.Text.Length;
for (int j = date.Fields.Count - 1; j >= i - 1; j--)
{
pos -= date.Fields[j].Text.Length;
}
date.SelectionStart = pos;
break;
}
}
}
}
}