找回密码
 立即注册

QQ登录

只需一步,快速开始

WangQingwei

注册会员

4

主题

5

帖子

40

积分

注册会员

积分
40

活字格认证

最新发帖
WangQingwei
注册会员   /  发表于:2010-1-27 16:01  /   查看:10007  /  回复:1
我想要实现的是:如果在单元格中输入的是数字,光标离开时,弹出MSG,并把光标返回原单元格。
问题是:我做了以下处理以后,光标会先返回原单元格,然后又移动到下一个单元格。有一个闪动的过程。
Public Class Form1

    Public Sub SetEnterKey(ByVal FpSpread As FarPoint.Win.Spread.FpSpread)
        Dim im As New FarPoint.Win.Spread.InputMap()

        ' 非編集セルでの[Enter]キーを「次列へ移動」とします
        im = FpSpread.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextColumnWrap)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.Shift), FarPoint.Win.Spread.SpreadActions.MoveToPreviousColumnWrap)

        ' 編集中セルでの[Enter]キーを「次列へ移動」とします
        im = FpSpread.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextColumnWrap)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.Shift), FarPoint.Win.Spread.SpreadActions.MoveToPreviousColumnWrap)

        '' SPREADにフォーカスを移動させます
        'FpSpread.Focus()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetEnterKey(Me.FpSpread1)
    End Sub

    Private Sub FpSpread1_Change(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.ChangeEventArgs) Handles FpSpread1.Change

        Dim intR As Integer = Me.FpSpread1.ActiveSheet.ActiveRowIndex

        If IsNumeric(FpSpread1.ActiveSheet.Cells(intR, 0).Value) Then
            MsgBox("IsNumeric,Focus Back!")
            Me.FpSpread1.ActiveSheet.SetActiveCell(intR, 0)
        End If

    End Sub

End Class

版本信息:
SPREAD for .NET 3.0J Windows Forms Edition リリースノート
Version 3.0.2010.2005

1 个回复

倒序浏览
郭鋭
初级会员   /  发表于:2010-7-26 15:53:00
沙发

不是办法的办法

本身没有什么好的办法。试一下下面这个吧,这个可以先解决你的可题。


Public Class Form1
    Dim intR As Integer = -1
    Dim intC As Integer = -1

    Public Sub SetEnterKey(ByVal FpSpread As FarPoint.Win.Spread.FpSpread)
        Dim im As New FarPoint.Win.Spread.InputMap()

        ' 非編集セルでの[Enter]キーを「次列へ移動」とします
        im = FpSpread.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextColumnWrap)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.Shift), FarPoint.Win.Spread.SpreadActions.MoveToPreviousColumnWrap)

        ' 編集中セルでの[Enter]キーを「次列へ移動」とします
        im = FpSpread.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextColumnWrap)
        im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.Shift), FarPoint.Win.Spread.SpreadActions.MoveToPreviousColumnWrap)

        '' SPREADにフォーカスを移動させます
        'FpSpread.Focus()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetEnterKey(Me.FpSpread1)
    End Sub

    Private Sub FpSpread1_Change(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.ChangeEventArgs) Handles FpSpread1.Change

        'Dim intR As Integer = Me.FpSpread1.ActiveSheet.ActiveRowIndex
        intR = Me.FpSpread1.ActiveSheet.ActiveRowIndex
        intC = Me.FpSpread1.ActiveSheet.ActiveColumnIndex

        If IsNumeric(FpSpread1.ActiveSheet.Cells(intR, intC).Value) Then
            MsgBox("IsNumeric,Focus Back!")
            'Me.FpSpread1.ActiveSheet.SetActiveCell(intR, 0)
        Else
            intR = -1
            intC = -1
        End If

    End Sub

    Private Sub FpSpread1_EnterCell(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EnterCellEventArgs) Handles FpSpread1.EnterCell
        If intR <> -1 Then Me.FpSpread1.ActiveSheet.SetActiveCell(intR, intC)
    End Sub
End Class
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部