デフォルトキーボードオペレーションのソースコード

CDefaultKeyboardOperationのインターフェースを実装するメソッドのソー スコードを掲載します。独自のキーボードオペレーションを作成する場 合は、このコードを参考にしてください。

Public Class CDefaultKeyboardOperation
    Implements IKeyboardOperation

    Public Enum EDirection
        COL
        ROW
    End Enum

    Public Direction As EDirection = EDirection.COL
    Public NextAsTab As Boolean = False
    Public LeaveOnLastField As Boolean = False

    Public Overridable Function ProcessDialogKey(ByVal key As System.Windows.Forms.Keys, ByVal table As UTable) As Boolean Implements IKeyboardOperation.ProcessDialogKey
        Select Case key
            Case Keys.Up, Keys.Down, Keys.Left, Keys.Right
                If table.FocusField Is Nothing Then
                    table.EntryFocus()
                Else
                    Select Case key
                        Case Keys.Up
                            Me.prevRow(table)
                        Case Keys.Down
                            Me.nextRow(table)
                        Case Keys.Left
                            Me.prevCol(table)
                        Case Keys.Right
                            Me.nextCol(table)
                    End Select
                End If
                Return True
            Case Keys.Home, Keys.End
                If table.FocusField IsNot Nothing Then
                    Select Case key
                        Case Keys.Home
                            Me.startCol(table)
                        Case Keys.End
                            Me.endCol(table)
                    End Select
                End If
                Return True
            Case Keys.PageDown
                Me.pageDown(table, table.VScrollBar)
                Return True
            Case Keys.PageUp
                Me.pageUp(table, table.VScrollBar)
                Return True
            Case Keys.Enter
                If table.FocusField Is Nothing Then
                    table.EntryFocus()
                    If table.FocusField Is Nothing Then
                        table.TopLevelControl.SelectNextControl(table, True, True, True, True)
                    End If
                Else
                    Dim handled As Boolean = False
                    table.RaiseFieldSelected(table.FocusField, handled)
                    If Not handled AndAlso table.StartEditing() Is Nothing Then
                        Me.next(table)
                    End If
                End If
                Return True
            Case Keys.Enter Or Keys.Shift
                If table.FocusField IsNot Nothing Then
                    Me.prev(table)
                    If table.FocusField Is Nothing Then
                        table.TopLevelControl.SelectNextControl(table, False, True, True, True)
                    End If
                    Return True
                End If
            Case Keys.Tab
                If Me.NextAsTab Then
                    If table.FocusField Is Nothing Then
                        table.EntryFocus()
                        If table.FocusField Is Nothing Then
                            table.TopLevelControl.SelectNextControl(table, True, True, True, True)
                        End If
                    Else
                        Me.next(table)
                    End If
                    Return True
                End If
            Case Keys.Tab Or Keys.Shift
                If Me.NextAsTab Then
                    If table.FocusField IsNot Nothing Then
                        Me.prev(table)
                        If table.FocusField Is Nothing Then
                            table.TopLevelControl.SelectNextControl(table, False, True, True, True)
                        End If
                        Return True
                    End If
                End If
            Case Keys.Delete
                If table.FocusField IsNot Nothing Then
                    If table.RaiseEditStarting(table.FocusField) = UTable.CSetting.EEditable.ALLOW Then
                        table.FocusField.Clear()
                    End If
                End If
        End Select
        Return False
    End Function

    Public Function EditorProcessDialogKey(ByVal key As System.Windows.Forms.Keys, ByVal table As UTable) As Boolean Implements IKeyboardOperation.EditorProcessDialogKey
        Select Case key
            Case Keys.Enter
                Me.next(table)
                Return True
            Case (Keys.Enter Or Keys.Shift)
                Me.prev(table)
                Return True
            Case Keys.Tab
                If NextAsTab Then
                    Me.next(table)
                    Return True
                End If
            Case (Keys.Tab Or Keys.Shift)
                If NextAsTab Then
                    Me.prev(table)
                    Return True
                End If
        End Select
        Return False
    End Function

    Public Overridable Sub LeaveEdit(ByVal direction As String, ByVal table As UTable) Implements IKeyboardOperation.LeaveEdit
        Select Case direction
            Case "UP"
                Me.prevRow(table)
            Case "DOWN"
                Me.nextRow(table)
            Case "LEFT"
                Me.prevCol(table)
            Case "RIGHT"
                Me.nextCol(table)
            Case "NEXT"
                Me.next(table)
            Case "PREV"
                Me.prev(table)
        End Select
    End Sub

    '以下略

End Class
目次へ戻る