PowerTools CalendarGrid for Windows Forms 1.0J
基本的な使い方(CalendarGcTextBoxCellType)

CalendarGcTextBoxCellTypeの基本的な使い方について説明します。


書式の設定

CalendarGcTextBoxCellTypeは、書式を設定することで入力可能な文字種を制限することができます。CalendarGcTextBoxCellTypeに設定可能な文字種等の詳細については、「書式を設定する」で解説しますので、ここではデザイナでCalendarGcTextBoxCellTypeに書式を設定する方法について説明します。

次は入力可能な文字種を全角のアルファベットに限定する例です。なお、文字種の全角および半角は、その文字のShift-JISコードを使って識別されます。

  1. デザイナを起動します。
  2. 任意のセルをCalendarGcTextBoxCellTypeに設定します。
  3. プロパティウィンドウのCellType.Formatプロパティをアクティブした時に表示される「…」ボタンを選択して、「書式の設定」フォームを表示します。
  4. リストから「A([全角]大文字アルファベット)」を選択します。
  5. OKボタンを選択します。
  6. デザイナを適用して終了します。

同じ書式をコードで設定する場合は次のようになります。

Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim GcTextBoxCellType As New InputManCell.CalendarGcTextBoxCellType()
GcTextBoxCellType.Format = "A"

Dim Template As New CalendarTemplate()
Template.RowCount = 2
Template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{DayOfWeek}"
Template.ColumnHeader.Columns(0).Width = 50
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 = GcTextBoxCellType.Clone()
Template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"

GcCalendarGrid1.Template = Template
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

var gcTextBoxCellType = new InputManCell.CalendarGcTextBoxCellType();
gcTextBoxCellType.Format = "A";

var template = new CalendarTemplate();
template.RowCount = 2;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
template.ColumnHeader.Columns[0].Width = 50;
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 = gcTextBoxCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";

gcCalendarGrid1.Template = template;


最大文字数の指定

MaxLengthUnitプロパティを使えば、MaxLengthプロパティでセルへの入能文字数を設定する際に文字ウント方法定することができます。MaxLengthUnitプロパティには、次の3つの設定値があります。バイト単位の処理では、各文字のバイト数はShift-JISコードを使って識別されます。

IVS文字はIVSの親となる漢字(以下、親字)の文字コードの後ろに異体字セレクタが付加された構造のため、MaxLengthプロパティの設定値によっては異体字セレクタが削除される場合があります。
以下はMaxLengthプロパティを「8」に設定し、親字「噌」を持つIVS文字「」を入力可能な最大文字数を入力した場合の動作例です。

MaxLengthUnitの値

動作例

Char

」は親字1文字、異体字セレクタ2文字の合計3文字としてカウントされます。よって、3文字目は親字のみの1文字が入力され、異体字セレクタ以降は削除されます。

Byte

」は親字2バイト、異体字セレクタ4バイトの合計6バイトとしてカウントされます。よって、2文字目は親字のみの2バイトが入力され、異体字セレクタ以降は削除されます。

TextElement

IVS文字は1文字としてカウントされるため、8文字のIVS文字がすべて入力されます。

なお、GcTextBox.SelectionStartプロパティとGcTextBox.SelectionLengthプロパティは、MaxLengthUnitプロパティの設定にかかわらずMaxLengthUnit.Charでカウントした結果と同じ文字単位で処理されます。


編集モードの切り替え

EditModeプロパティを使って、セルがフォーカスを受け取ったときのデフォルトの編集モードを定義できます。EditModeプロパティをEditMode.Insertにすると挿入モード、EditMode.Overwriteにすると上書きモードになります。また、EditMode.FixedInsertとEditMode.FixedOverwriteでは、編集モードが固定されるので、実行中に[Ins]キーが押されても編集モードは切り替わりません。

セルの編集時では、EditModeプロパティがEditMode.InsertまたはEditMode.Overwriteに設定されている場合、編集モードが[Ins]キーまたはEditModeプロパティによって変更されたときには、GcTextBox.EditStatusChangedイベントが発生します。また、GcTextBox.Overwriteプロパティを使って編集モードを調べることができます。

次のサンプルコードは、GcTextBox.KeyDownイベントで [Alt] キーおよび [C] キーが押下されたとき、GcTextBox.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 GcTextBoxCellType As New InputManCell.CalendarGcTextBoxCellType()
    GcTextBoxCellType.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 = 50
    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 = GcTextBoxCellType.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.GcTextBox 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.GcTextBox = DirectCast(sender, CalendarGridInputMan.GcTextBox)

    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 gcTextBoxCellType = new InputManCell.CalendarGcTextBoxCellType();
    gcTextBoxCellType.EditMode = InputManCell.EditMode.Insert;

    var template = new CalendarTemplate();
    template.RowCount = 3;
    template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
    template.ColumnHeader.Columns[0].Width = 50;
    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 = gcTextBoxCellType.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.GcTextBox)
    {
        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.GcTextBox;

    if (e.Alt && e.KeyCode == Keys.C)
    {
        if (editor.OverWrite == true)
        {
            Console.WriteLine("上書き");
        }
        else
        {
            Console.WriteLine("挿入");
        }
    }
}


イベントを使った文字列操作

セルの編集時のみ有効です。

セルに文字列を入力すると GcTextBox.TextChanging イベントが、GcTextBox.TextChanged イベントの前(入力された文字列がText プロパティに渡される前)に発生します。このイベント内で入力文字列をチェックすれば、Text プロパティの値に影響を与えることなく、入力を制御できます。


コンテキストメニューの表示

CalendarGridの他のセル型の場合と同様です。CalendarGcTextBoxCellType.ContextMenuStripプロパティを使用します。


参照

 

 


© 2014 GrapeCity inc. All rights reserved.