1
flexgrid, 두 개의 명령 단추 및 텍스트 상자로 구성된 VB6 응용 프로그램이 있습니다. 사용자가 위 또는 아래 화살표 키를 눌러 격자의 행을 전환 할 수 있도록하는 코드가 있습니다. 아래쪽 화살표 키를 누르면 커서가 다음 행의 텍스트 끝에 놓이지 만 위쪽 화살표 키를 누르면 커서가 이전 행의 텍스트 중간에 놓입니다. 아무도 이것에 대한 explantion 있나요?vbkeyup이이 코드에서 vbkeydown과 다른 결과를 생성하는 이유
Private Sub Command1_Click()
With MSFlexGrid1
.Cols = 4
.Rows = 5
.FixedCols = 1
.FixedRows = 1
MSFlexGrid1.TextMatrix(0, 1) = "FROM"
MSFlexGrid1.TextMatrix(0, 2) = "THRU"
MSFlexGrid1.TextMatrix(0, 3) = "PAGE"
MSFlexGrid1.TextMatrix(1, 1) = "Aa"
MSFlexGrid1.TextMatrix(1, 2) = "Az"
MSFlexGrid1.TextMatrix(1, 3) = "-"
MSFlexGrid1.TextMatrix(2, 1) = "Ba"
MSFlexGrid1.TextMatrix(2, 2) = "Bz"
MSFlexGrid1.TextMatrix(2, 3) = "-"
MSFlexGrid1.TextMatrix(3, 1) = "Ca"
MSFlexGrid1.TextMatrix(3, 2) = "Cz"
MSFlexGrid1.TextMatrix(3, 3) = "-"
MSFlexGrid1.TextMatrix(4, 1) = "Da"
MSFlexGrid1.TextMatrix(4, 2) = "Dz"
MSFlexGrid1.TextMatrix(4, 3) = "-"
End With
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Visible = False
End Sub
Private Sub MSFlexGrid1_DblClick()
FlexGridEdit Asc(" ")
Exit Sub
End Sub
Private Sub FlexGridEdit(KeyAscii As Integer)
Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
Text1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.Col) - 2 * (MSFlexGrid1.ColWidth (MSFlexGrid1.Col) - MSFlexGrid1.CellWidth)
Text1.Height = MSFlexGrid1.RowHeight(MSFlexGrid1.Row) - 2 * (MSFlexGrid1.RowHeight(MSFlexGrid1.Row) - MSFlexGrid1.CellHeight)
Text1.MaxLength = 2
Text1.Visible = True
Text1.SetFocus
Select Case KeyAscii
Case 0 To Asc(" ")
Text1.Text = MSFlexGrid1.Text
Text1.SelStart = Len(Text1.Text)
Case Else
Text1.Text = Chr$(KeyAscii)
Text1.SelStart = 1
End Select
Exit Sub
End Sub
Function ValidateFlexGrid1() As Boolean
Dim llCntrRow As Integer
Dim llCntrCol As Integer
Dim max_len As Single
Dim new_len As Single
Dim liCntr As Integer
Dim lsCheck As String
With MSFlexGrid1
If Text1.Visible Then .Text = Text1.Text
If .Rows = .FixedRows Then
ValidateFlexGrid1 = False
End If
For llCntrCol = .FixedCols To MSFlexGrid1.Cols - 1
For llCntrRow = .FixedRows To MSFlexGrid1.Rows - 1
If .TextMatrix(llCntrRow, llCntrCol) = "" Then
ValidateFlexGrid1 = False
Exit Function
End If
Next llCntrRow
Next llCntrCol
End With
ValidateFlexGrid1 = True
Exit Function
End Function
Private Sub Text1_Keydown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyRight, vbKeyLeft, vbKeyReturn
If Text1.Visible = True Then
If Text1.Text = "/" Then
If MSFlexGrid1.Row > 1 Then
Text1.Text = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row - 1, MSFlexGrid1.Col)
Text1.SelStart = Len(Text1.Text)
End If
End If
MSFlexGrid1.Text = Text1.Text
If KeyCode = vbKeyRight Or KeyCode = vbKeyReturn Then
If Text1.SelStart = Len(Text1.Text) Then
FlexGridChkPos KeyCode
FlexGridEdit Asc(" ")
End If
Else
If Text1.SelStart = 0 Then
FlexGridChkPos KeyCode
FlexGridEdit Asc(" ")
End If
End If
End If
Case vbKeyDown, vbKeyUp
If Text1.Visible = True Then
MSFlexGrid1.Text = Text1.Text
FlexGridChkPos KeyCode
FlexGridEdit Asc(" ")
End If
End Select
Exit Sub
End Sub
Function FlexGridChkPos(KeyCode As Integer) As Boolean
Dim llNextRow As Long
Dim llNextCol As Long
Dim llCurrCol As Long
Dim llCurrRow As Long
Dim llTotCols As Long
Dim llTotRows As Long
Dim llBegRow As Long
Dim llBegCol As Long
Dim llCntrCol As Long
Dim lsText As String
With MSFlexGrid1
llCurrRow = .Row + 1
llCurrCol = .Col + 1
llTotRows = .Rows
llTotCols = .Cols
llBegRow = .FixedRows
llBegCol = .FixedCols
If KeyCode = vbKeyRight Or KeyCode = vbKeyReturn Then
llNextCol = llCurrCol + 1
If llNextCol > llTotCols Then
llNextRow = llCurrRow + 1
If llNextRow > llTotRows Then
.Rows = .Rows + 1
llCurrRow = llCurrRow + 1
llCurrCol = 1 + llBegCol
Else
llCurrRow = llNextRow
llCurrCol = 1 + llBegCol
End If
Else
llCurrCol = llNextCol
End If
End If
If KeyCode = vbKeyLeft Then
llNextCol = llCurrCol - 1
If llNextCol = llBegCol Then
llNextRow = llCurrRow - 1
If llNextRow = llBegRow Then
llCurrRow = llTotRows
Else
llCurrRow = llNextRow
End If
llCurrCol = llTotCols
Else
llCurrCol = llNextCol
End If
End If
If KeyCode = vbKeyUp Then
llNextRow = llCurrRow - 1
If llNextRow = llBegRow Then
llCurrRow = llTotRows
Else
llCurrRow = llNextRow
End If
End If
If KeyCode = vbKeyDown Then
llNextRow = llCurrRow + 1
If llNextRow > llTotRows Then
llCurrRow = llBegRow + 1
Else
llCurrRow = llNextRow
End If
End If
.Col = llCurrCol - 1
.Row = llCurrRow - 1
End With
Exit Function
End Function
고마워요. 이것은 나를 미치게했다. 키 코드를 0으로 설정하면 고정되어있는 것 같습니다. –