CalendarGcCharMaskCellTypeの基本的な使い方について説明します。
入力方向の設定
CalendarGcCharMaskCellType.InputDirectionプロパティを使用します。
CalendarGcCharMaskCellTypeでは、InputDirectionプロパティを使って、テキストの入力方向を設定することができます。セルへの入力内容に応じてテキストの入力方向を設定することで、自然な入力を実現することができます。
たとえば、文字列や番号のような入力の場合、LeftToRight(左から右へ)、数値や金額などを入力する場合はRightToLeft(右から左へ)のように設定することができます。
- InputDirection.LeftToRight の例



- InputDirection.RightToLeft の例

次のサンプルコードは、入力方向を右から左に設定する例です。
Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan
gcCharMaskCellType.InputDirection = InputMan.CharMaskInputDirection.RightToLeft
Dim Template As New CalendarTemplate()
Template.RowCount = 2
Template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{DayOfWeek}"
Template.ColumnHeader.Columns(0).Width = 200
Template.Content.Rows(0).Cells(0).DateFormat = "{MonthDay}"
Template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
Template.Content.Rows(1).Cells(0).Name = "myCell1"
Template.Content.Rows(1).Cells(0).CellType = gcCharMaskCellType.Clone()
Template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"
GcCalendarGrid1.Template = Template
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;
var gcCharMaskCellType = new InputManCell.CalendarGcCharMaskCellType();
gcCharMaskCellType.InputDirection = InputManCell.CharMaskInputDirection.RightToLeft;
var template = new CalendarTemplate();
template.RowCount = 3;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
template.ColumnHeader.Columns[0].Width = 200;
template.Content.Rows[0].Cells[0].DateFormat = "{MonthDay}";
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Name = "myCell1";
template.Content.Rows[1].Cells[0].CellType = gcCharMaskCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";
gcCalendarGrid1.Template = template;
編集モードの切り替え
CalendarGcCharMaskCellType.EditModeプロパティを使用します。
EditModeプロパティを使って、セルがフォーカスを受け取ったときのデフォルトの編集モードを定義できます。EditModeプロパティをEditMode.Insertにすると挿入モード、EditMode.Overwriteにすると上書きモードになります。また、EditMode.FixedInsertとEditMode.FixedOverwriteでは、編集モードが固定されるので、実行中に[Ins]キーが押されても編集モードは切り替わりません。
編集モードが上書きモードの場合、下図のようにカレット位置のマス目が反転表示されます。

セルの編集時では、EditModeプロパティがEditMode.InsertまたはEditMode.Overwriteに設定されている場合、編集モードが[Ins]キーまたはEditModeプロパティによって変更されたときには、GcCharMask.EditStatusChangedイベントが発生します。また、GcCharMask.Overwriteプロパティを使って編集モードを調べることができます。
次のサンプルコードは、GcCharMask.KeyDownイベントで[Alt]キーおよび[C]キーが押下されたとき、GcCharMask.Overwriteプロパティを使用して編集モードを取得します。
Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan
Imports CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim GcCharMaskCellType As New InputManCell.CalendarGcCharMaskCellType()
GcCharMaskCellType.EditMode = InputManCell.EditMode.Insert
Dim Template As New CalendarTemplate()
Template.RowCount = 2
Template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{DayOfWeek}"
Template.ColumnHeader.Columns(0).Width = 200
Template.Content.Rows(0).Cells(0).DateFormat = "{MonthDay}"
Template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
Template.Content.Rows(1).Cells(0).Name = "myCell1"
Template.Content.Rows(1).Cells(0).CellType = GcCharMaskCellType.Clone()
Template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"
GcCalendarGrid1.Template = Template
AddHandler GcCalendarGrid1.EditingControlShowing, AddressOf GcCalendarGrid1_EditingControlShowing
End Sub
Private Sub GcCalendarGrid1_EditingControlShowing(sender As Object, e As CalendarEditingControlShowingEventArgs)
If TypeOf e.Control Is CalendarGridInputMan.GcCharMask Then
RemoveHandler e.Control.KeyDown, AddressOf Editor_KeyDown
AddHandler e.Control.KeyDown, AddressOf Editor_KeyDown
End If
End Sub
Private Sub Editor_KeyDown(sender As Object, e As KeyEventArgs)
Dim editor As CalendarGridInputMan.GcCharMask = DirectCast(sender, CalendarGridInputMan.GcCharMask)
If e.Alt AndAlso e.KeyCode = Keys.C Then
If editor.OverWrite = True Then
Console.WriteLine("上書き")
Else
Console.WriteLine("挿入")
End If
End If
End Sub
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;
using CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors;
private void Form1_Load(object sender, EventArgs e)
{
var gcCharMaskCellType = new InputManCell.CalendarGcCharMaskCellType();
gcCharMaskCellType.InputDirection = InputManCell.CharMaskInputDirection.RightToLeft;
var template = new CalendarTemplate();
template.RowCount = 3;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
template.ColumnHeader.Columns[0].Width = 200;
template.Content.Rows[0].Cells[0].DateFormat = "{MonthDay}";
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Name = "myCell1";
template.Content.Rows[1].Cells[0].CellType = gcCharMaskCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";
gcCalendarGrid1.Template = template;
gcCalendarGrid1.EditingControlShowing += gcCalendarGrid1_EditingControlShowing;
}
private void gcCalendarGrid1_EditingControlShowing(object sender, CalendarEditingControlShowingEventArgs e)
{
if (e.Control is CalendarGridInputMan.GcCharMask)
{
e.Control.KeyDown -= new KeyEventHandler(Editor_KeyDown);
e.Control.KeyDown += new KeyEventHandler(Editor_KeyDown);
}
}
private void Editor_KeyDown(object sender, KeyEventArgs e)
{
var editor = sender as CalendarGridInputMan.GcCharMask;
if (e.Alt && e.KeyCode == Keys.C)
{
if (editor.OverWrite == true)
{
Console.WriteLine("上書き");
}
else
{
Console.WriteLine("挿入");
}
}
}
リテラル文字を含まない値の取得と設定
CalendarGcCharMaskCellType.Valueプロパティを使用します。
クリップボードにリテラル文字を含まない値を渡すには、ClipContentプロパティとGcCharMask.SelectedTextプロパティを使用します。ClipContentプロパティで制御できるのは、SelectedTextプロパティの値のみです。なお、プロンプト文字列は、ClipContentプロパティの設定に関わらず常にクリップボードに渡されます。
次のサンプルコードは、ClipContentプロパティを使って、リテラル文字列を省いた文字列をクリップボードにコピーする方法を示します。
Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan
Imports CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim GcCharMaskCellType As New InputManCell.CalendarGcCharMaskCellType()
' マス目をクリアします。
GcCharMaskCellType.CharBoxes.Clear()
' 書式を設定します。
GcCharMaskCellType.Format = "9"
' 郵便番号用のマス目を設定します。
GcCharMaskCellType.CharBoxes.Add(New InputManCell.LiteralBox("〒"))
GcCharMaskCellType.CharBoxes.Add(New InputManCell.InputBox())
GcCharMaskCellType.CharBoxes.Add(New InputManCell.InputBox())
GcCharMaskCellType.CharBoxes.Add(New InputManCell.InputBox())
GcCharMaskCellType.CharBoxes.Add(New InputManCell.SeparatorBox())
GcCharMaskCellType.CharBoxes.Add(New InputManCell.InputBox())
GcCharMaskCellType.CharBoxes.Add(New InputManCell.InputBox())
GcCharMaskCellType.CharBoxes.Add(New InputManCell.InputBox())
GcCharMaskCellType.CharBoxes.Add(New InputManCell.InputBox())
GcCharMaskCellType.ClipContent = InputManCell.ClipContent.ExcludeLiterals
Dim template As New CalendarTemplate()
template.RowCount = 3
template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{DayOfWeek}"
template.ColumnHeader.Columns(0).Width = 120
template.Content.Rows(0).Cells(0).DateFormat = "{MonthDay}"
template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.Content.Rows(1).Cells(0).Name = "myCell1"
template.Content.Rows(1).Cells(0).CellType = GcCharMaskCellType.Clone()
template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"
template.Content.Rows(1).Cells(0).Value = "9813205"
GcCalendarGrid1.Template = template
AddHandler GcCalendarGrid1.EditingControlShowing, AddressOf GcCalendarGrid1_EditingControlShowing
End Sub
Private Sub GcCalendarGrid1_EditingControlShowing(sender As Object, e As CalendarEditingControlShowingEventArgs)
If TypeOf e.Control Is CalendarGridInputMan.GcCharMask Then
RemoveHandler e.Control.KeyDown, AddressOf Editor_KeyDown
AddHandler e.Control.KeyDown, AddressOf Editor_KeyDown
End If
End Sub
Private Sub Editor_KeyDown(sender As Object, e As KeyEventArgs)
Dim cell As CalendarCell = GcCalendarGrid1(GcCalendarGrid1.CurrentCellPosition.Date) _
(GcCalendarGrid1.CurrentCellPosition.RowIndex, GcCalendarGrid1.CurrentCellPosition.ColumnIndex)
Dim editor As CalendarGridInputMan.GcCharMask = DirectCast(sender, CalendarGridInputMan.GcCharMask)
If e.KeyCode = Keys.F5 Then
' クリップボードにコピーします。
editor.SelectionStart = 0
editor.SelectionLength = editor.Text.Length
Clipboard.SetDataObject(editor.SelectedText)
' クリップボードのデータを取得して確認します。
Dim cbData As IDataObject = Clipboard.GetDataObject()
GcCalendarGrid1(GcCalendarGrid1.CurrentCellPosition.Date)(cell.RowIndex + 1, cell.ColumnIndex).Value =
cbData.GetData(DataFormats.Text).ToString()
End If
End Sub
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;
using CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors;
private void Form1_Load(object sender, EventArgs e)
{
var gcCharMaskCellType = new InputManCell.CalendarGcCharMaskCellType();
// マス目をクリアします。
gcCharMaskCellType.CharBoxes.Clear();
// 書式を設定します。
gcCharMaskCellType.Format = "9";
// 郵便番号用のマス目を設定します。
gcCharMaskCellType.CharBoxes.Add(new InputManCell.LiteralBox("〒"));
gcCharMaskCellType.CharBoxes.Add(new InputManCell.InputBox());
gcCharMaskCellType.CharBoxes.Add(new InputManCell.InputBox());
gcCharMaskCellType.CharBoxes.Add(new InputManCell.InputBox());
gcCharMaskCellType.CharBoxes.Add(new InputManCell.SeparatorBox());
gcCharMaskCellType.CharBoxes.Add(new InputManCell.InputBox());
gcCharMaskCellType.CharBoxes.Add(new InputManCell.InputBox());
gcCharMaskCellType.CharBoxes.Add(new InputManCell.InputBox());
gcCharMaskCellType.CharBoxes.Add(new InputManCell.InputBox());
gcCharMaskCellType.ClipContent = InputManCell.ClipContent.ExcludeLiterals;
var template = new CalendarTemplate();
template.RowCount = 3;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
template.ColumnHeader.Columns[0].Width = 200;
template.Content.Rows[0].Cells[0].DateFormat = "{MonthDay}";
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Name = "myCell1";
template.Content.Rows[1].Cells[0].CellType = gcCharMaskCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Value = "9813205";
gcCalendarGrid1.Template = template;
gcCalendarGrid1.EditingControlShowing += gcCalendarGrid1_EditingControlShowing;
}
private void gcCalendarGrid1_EditingControlShowing(object sender, CalendarEditingControlShowingEventArgs e)
{
if (e.Control is CalendarGridInputMan.GcCharMask)
{
e.Control.KeyDown -= new KeyEventHandler(Editor_KeyDown);
e.Control.KeyDown += new KeyEventHandler(Editor_KeyDown);
}
}
private void Editor_KeyDown(object sender, KeyEventArgs e)
{
CalendarCell cell = gcCalendarGrid1[gcCalendarGrid1.CurrentCellPosition.Date]
[gcCalendarGrid1.CurrentCellPosition.RowIndex, gcCalendarGrid1.CurrentCellPosition.ColumnIndex];
var editor = sender as CalendarGridInputMan.GcCharMask;
if (e.KeyCode == Keys.F5)
{
// クリップボードにコピーします。
editor.SelectionStart = 0;
editor.SelectionLength = editor.Text.Length;
Clipboard.SetDataObject(editor.SelectedText);
// クリップボードのデータを取得して確認します。
IDataObject cbData = Clipboard.GetDataObject();
gcCalendarGrid1[gcCalendarGrid1.CurrentCellPosition.Date][cell.RowIndex + 1, cell.ColumnIndex].Value =
cbData.GetData(DataFormats.Text).ToString();
}
}
コンテキストメニューの表示
CalendarGridの他のセル型の場合と同様です。CalendarGcCharMaskCellType.ContextMenuStripを使用します。
関連トピック