Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If ActiveControl Is Text1 Then
Select Case KeyCode
Case vbKeyReturn
With MSFlexGrid1
.TextMatrix(.Row, .Col) = Text1.Text
.CellAlignment = .CellAlignment
End With
Text1.Visible = False
Case vbKeyEscape
With MSFlexGrid1
Text1.Text = .TextMatrix(.Row, .Col)
End With
Text1.Visible = False
End Select
End If
End Sub
Private Sub Form_Load()
Text1.Visible = False
KeyPreview = True
With MSFlexGrid1
.Cols = 3
.Rows = 4
End With
End Sub
Private Sub MSFlexGrid1_DblClick()
With MSFlexGrid1
Text1.BorderStyle = 0
Text1.BackColor = vbYellow
Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
Select Case .CellAlignment
Case flexAlignGeneral, flexAlignLeftBottom, flexAlignLeftCenter, flexAlignLeftTop
Text1.Alignment = vbLeftJustify
Case flexAlignCenterBottom, flexAlignCenterCenter, flexAlignCenterTop
Text1.Alignment = vbCenter
Case flexAlignRightBottom, flexAlignRightCenter, flexAlignRightTop
Text1.Alignment = vbRightJustify
End Select
Text1.Text = .TextMatrix(.Row, .Col)
Text1.Visible = True
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End With
End Sub
Private Sub MSFlexGrid1_EnterCell()
If Text1.Visible Then
MSFlexGrid1_DblClick
Else
MSFlexGrid1.CellBackColor = vbYellow
End If
End Sub
Private Sub MSFlexGrid1_LeaveCell()
With MSFlexGrid1
If Text1.Visible Then
.TextMatrix(.Row, .Col) = Text1.Text
.CellAlignment = .CellAlignment
End If
.CellBackColor = vbWindowBackground
End With
End Sub