VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5355
ClientLeft = 1545
ClientTop = 1920
ClientWidth = 6420
LinkTopic = "Form1"
ScaleHeight = 5355
ScaleWidth = 6420
Begin VB.PictureBox Picture1
Height = 3495
Left = 1230
ScaleHeight = 3435
ScaleWidth = 3495
TabIndex = 0
Top = 990
Width = 3555
Begin VB.TextBox txtEdit
Height = 405
Left = 1260
TabIndex = 1
Top = 1440
Width = 1665
End
Begin MSFlexGridLib.MSFlexGrid mfgGrid
Height = 3585
Left = 0
TabIndex = 2
Top = 0
Width = 3795
_ExtentX = 6694
_ExtentY = 6324
_Version = 393216
Rows = 20
FixedRows = 0
FixedCols = 0
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private glngX As Long
Private glngY As Long
Private blnChanged As Boolean
Private blnInEdit As Boolean
Private lngRowHeight As Long
Private Sub TextSelectAll(Tb As TextBox)
With Tb
.SelStart = 0
.SelStart = 32767
End With
End Sub
Private Sub ShowErr()
MsgBox Err.Description, vbCritical
End Sub
Private Sub Form_Load()
With Screen
glngX = .TwipsPerPixelX
glngY = .TwipsPerPixelY
End With
Private Sub MoveTextBox()
With mfgGrid
If .Rows > 0 Then
Dim lh As Long
lh = .RowHeight(0)
Dim lt As Long
lt = (.Row - .TopRow) * lh
If .Col = 0 Then
Dim ll As Long
ll = 0
Dim lw As Long
lw = .ColWidth(0)
Else
ll = .ColWidth(0)
lw = .ColWidth(1)
End If
txtEdit.Move ll, lt, lw - glngX, lh - glngY
End If
End With
End Sub
Private Sub mfgGrid_EnterCell()
On Error GoTo ErrorHandle
With mfgGrid
txtEdit = .Text
blnChanged = False
MoveTextBox
End With
Exit Sub
ErrorHandle:
ShowErr
End Sub
Private Sub mfgGrid_KeyPress(KeyAscii As Integer)
On Error GoTo ErrorHandle
With mfgGrid
Dim l As Long
l = .Row
If l >= 0 Then
Select Case KeyAscii
Case 0 To &H1F
Case Else
Dim s As String
s = .Text
blnInEdit = True
With txtEdit
If KeyAscii = vbKeySpace Then
.Text = s
blnChanged = False
TextSelectAll txtEdit
.SetFocus
Else
.Text = vbNullString
.SetFocus
SendKeys Chr$(KeyAscii), True
End If
End With
End Select
End If
End With
Exit Sub
ErrorHandle:
If Err <> 381 Then ShowErr
End Sub
Private Sub mfgGrid_LeaveCell()
On Error GoTo ErrorHandle
txtEdit_LostFocus
Exit Sub
ErrorHandle:
ShowErr
End Sub
Private Sub mfgGrid_Scroll()
On Error GoTo ErrorHandle
MoveTextBox
Exit Sub
ErrorHandle:
ShowErr
End Sub
Private Sub txtEdit_Change()
blnChanged = True
End Sub
Private Sub txtEdit_Click()
If Not blnInEdit Then
On Error GoTo ErrorHandle
mfgGrid_KeyPress vbKeySpace
End If
Exit Sub
ErrorHandle:
ShowErr
End Sub
Private Sub txtEdit_KeyPress(KeyAscii As Integer)
On Error GoTo ErrorHandle
Select Case KeyAscii
Case vbKeyEscape
txtEdit = mfgGrid.Text
blnChanged = False
GoTo SetFocusToGrid
Case vbKeyReturn
SetFocusToGrid:
KeyAscii = 0
mfgGrid.SetFocus
End Select
Exit Sub
ErrorHandle:
ShowErr
End Sub
Private Sub txtEdit_LostFocus()
blnInEdit = False
On Error GoTo ErrorHandle
If blnChanged Then
With txtEdit
If .Visible Then
.SelStart = 0
Dim s As String
mfgGrid.Text = .Text
End If
End With
blnChanged = False
End If
Exit Sub
ErrorHandle:
txtEdit = mfgGrid.Text
blnChanged = False
ShowErr
End Sub