''' <summary> ''' 下矢印の動作クラス ''' </summary> ''' <remarks></remarks> Public Class DownArrowActionDouble ' Actionクラスを継承したサブクラスを作成します Inherits FarPoint.Win.Spread.Action Public Event FormartRow(ByVal sender As Object, ByVal e As FormatRowEventArgs) Public Event CheckRow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Public Event LeaveCellArrow(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.LeaveCellEventArgs) Public Overrides Sub PerformAction(ByVal sender As Object) If TypeOf sender Is FarPoint.Win.Spread.SpreadView Then ' アクティブシートを取得します Dim spread As FarPoint.Win.Spread.SpreadView = CType(sender, FarPoint.Win.Spread.SpreadView) Dim sheet As FarPoint.Win.Spread.SheetView = spread.Sheets(spread.ActiveSheetIndex) ' アクティブセルの行列インデックスを取得します Dim Row As Integer = sheet.ActiveRowIndex Dim Col As Integer = sheet.ActiveColumnIndex Dim EvenRow As Integer Dim OddROw As Integer If Row Mod 2 = 0 Then EvenRow = Row OddROw = Row + 1 Else EvenRow = Row - 1 OddROw = Row End If ' 移動先のセルの行列インデックス用変数を宣言します Dim NewRow As Integer Dim NewColumn As Integer Dim isAddRow As Boolean isAddRow = (Row = sheet.RowCount - 1 OrElse (Row = sheet.RowCount - 2 And sheet.Cells(Row + 1, Col).Locked = True)) Dim isMoveNext As Boolean isMoveNext = True Dim e As New System.ComponentModel.CancelEventArgs If Row = OddROw OrElse (Row = EvenRow And sheet.Cells(Row + 1, Col).Locked = True) Then RaiseEvent CheckRow(Me, e) End If isMoveNext = Not e.Cancel If isAddRow And e.Cancel = False Then sheet.RowCount = sheet.RowCount + 2 RaiseEvent FormartRow(Me, New FormatRowEventArgs(sheet.RowCount - 2, Col)) End If If isMoveNext Then NewRow = Row For i As Integer = Row + 1 To sheet.RowCount - 1 If sheet.Cells(i, Col).Locked = False Then NewRow = i Exit For End If Next NewColumn = Col End If ' 移動先のセルがシート上に存在する場合 If isMoveNext = True And NewRow < sheet.RowCount And NewColumn < sheet.ColumnCount Then Dim ss1 As FarPoint.Win.Spread.SpreadView = spread.GetRootWorkbook RaiseEvent LeaveCellArrow(spread, New FarPoint.Win.Spread.LeaveCellEventArgs(ss1, Row, Col, NewRow, NewColumn)) ' アクティブセルを設定します sheet.SetActiveCell(NewRow, NewColumn) spread.ShowActiveCell(FarPoint.Win.Spread.VerticalPosition.Nearest, FarPoint.Win.Spread.HorizontalPosition.Nearest) End If End If End Sub End Class Public Class CheckRowEventArgs Inherits System.ComponentModel.CancelEventArgs Dim m_IsBlankRow As Boolean Public Property IsBlankRow() As Boolean Get Return m_IsBlankRow End Get Set(ByVal value As Boolean) m_IsBlankRow = value End Set End Property End Class Public Class FormatRowEventArgs Inherits EventArgs Public Sub New(ByVal fRow As Integer, ByVal fCol As Integer) m_FormatRow = fRow m_FormatCol = fCol End Sub Dim m_FormatRow As Integer Public Property FormatRow() As Integer Get Return m_FormatRow End Get Set(ByVal value As Integer) m_FormatRow = value End Set End Property Dim m_FormatCol As Integer Public Property FormatCol() As Integer Get Return m_FormatCol End Get Set(ByVal value As Integer) m_FormatCol = value End Set End Property End Class
' アクションをマッピングします Dim am As FarPoint.Win.Spread.ActionMap = ssBody.GetActionMap() Dim ac As New DownArrowActionDouble() AddHandler ac.CheckRow, AddressOf FpSpead1_CheckRow AddHandler ac.FormartRow, AddressOf FpSpead1_FormartRow AddHandler ac.LeaveCellArrow, AddressOf ssBodyFpSpead1_LeaveCell am.Put("CustomAction", ac) im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Down, Keys.None), "CustomAction") Private Sub FpSpead1_CheckRow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) End Sub Private Sub FpSpead1_FormartRow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) End Sub Private Sub FpSpead1_LeaveCell(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.LeaveCellEventArgs) End Sub