从spread中移出焦点

    Dim enterFlg As Boolean = False

       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cmb_yyyymm.Items.Add(DateTime.Today.Year & "/" & Format(DateTime.Now.AddMonths(-2).Month, "00"))
        Me.cmb_yyyymm.Items.Add(DateTime.Today.Year & "/" & Format(DateTime.Now.AddMonths(-1).Month, "00"))
        Me.cmb_yyyymm.Items.Add(DateTime.Today.Year & "/" & Format(DateTime.Today.Month, "00"))
        Me.cmb_yyyymm.DropDownStyle = ComboBoxStyle.DropDownList
        Me.cmb_yyyymm.SelectedIndex = 2

        Me.FpSpread1.EditModePermanent = False
        '' 編集中セルの Enterキー押下による動作を無効とする。
        Dim im As New FarPoint.Win.Spread.InputMap
        'im = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)
        'im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.None)
        '[F2]:編集開始
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.F2, Keys.None), _
                                        FarPoint.Win.Spread.SpreadActions.StartEditing)
        'フォーカス時のEnterキー押下による動作を「次列へ移動」とします。
        im = FpSpread1.GetInputMap(InputMapMode.WhenFocused)
        im.Put(New Keystroke(Keys.Enter, Keys.None), SpreadActions.MoveToNextColumnWrap)
        im.Put(New Keystroke(Keys.Tab, Keys.None), SpreadActions.MoveToNextColumnWrap)

    End Sub

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then
            If e.Control = False Then
                If Not TypeOf Me.ActiveControl Is FarPoint.Win.Spread.FpSpread Then
                    Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
                End If
            End If
        End If
    End Sub

    Private Sub FpSpread1_Advance(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.AdvanceEventArgs) Handles FpSpread1.Advance
        If enterFlg And e.AdvanceNext Or (FpSpread1.ActiveSheet.ActiveColumnIndex = 0 And FpSpread1.ActiveSheet.ActiveColumnIndex = 0) Then
            If FpSpread1.ActiveSheet.ActiveRowIndex = FpSpread1.ActiveSheet.RowCount - 1 And _
              FpSpread1.ActiveSheet.ActiveColumnIndex = FpSpread1.ActiveSheet.ColumnCount - 1 Then
                '最終セルでのEnterキー押下によってアクティブセルを先頭に位置付けます
                e.Cancel = True
                Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
            Else
                Me.SelectNextControl(Me.ActiveControl, False, True, True, True)
            End If
            enterFlg = False
        End If
    End Sub

    Private Sub FpSpread1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles FpSpread1.KeyDown
        enterFlg = False
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then
            'Enterキー押下を検知
            enterFlg = True
        End If
    End Sub 

你可能感兴趣的:(从spread中移出焦点)