📄 frmmultiplication_table.frm
字号:
'Restore currently selected cell
MSFlexGrid1.Row = New_Row
MSFlexGrid1.Col = New_Col
'Redraw the control
MSFlexGrid1.Redraw = True
End Sub
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
'See if mouse is over the control
If IsMouseOver(MSFlexGrid1) Then
'If Key down on fixed row / columns, exit sub
If MSFlexGrid1.MouseRow <= MSFlexGrid1.FixedRows - 1 Or MSFlexGrid1.MouseCol <= MSFlexGrid1.FixedCols - 1 Then Exit Sub
Select Case KeyCode
Case vbKeyF11 'Keyboard "F11" key pressed
SetEquation 'Gosub to set cell selection and tool tip
End Select
End If
DoEvents
End Sub
Private Sub MSFlexGrid1_LostFocus()
'If focus is lost to another control or window, remove the tool tip
'Turn off the redraw to stop flicker of grid control
MSFlexGrid1.Redraw = False
'Save the current selected cell
New_Row = MSFlexGrid1.Row
New_Col = MSFlexGrid1.Col
'Reset color of last selected row fixed cell(s) on control lost focus
For c = 0 To MSFlexGrid1.FixedCols - 1
'Select and reset colors on old row
MSFlexGrid1.Col = c
MSFlexGrid1.Row = LastSelected_Row
MSFlexGrid1.CellForeColor = MSFlexGrid1.ForeColorFixed
MSFlexGrid1.CellBackColor = MSFlexGrid1.BackColorFixed
Next c
'Reset color of last selected column fixed cell(s) on control lost focus
For r = 0 To MSFlexGrid1.FixedRows - 1
'Select and reset colors on old column
MSFlexGrid1.Row = r
MSFlexGrid1.Col = LastSelected_Col
MSFlexGrid1.CellForeColor = MSFlexGrid1.ForeColorFixed
MSFlexGrid1.CellBackColor = MSFlexGrid1.BackColorFixed
Next r
'Restore currently selected cell
MSFlexGrid1.Row = New_Row
MSFlexGrid1.Col = New_Col
'Redraw the control
MSFlexGrid1.Redraw = True
'Set some form display values
MSFlexGrid1_Tip.Remove
txtTipState.Text = "禁止"
Picture1.Visible = False
DoEvents
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'See if mouse is over the control
If IsMouseOver(MSFlexGrid1) Then
'If mouse button down is on fixed row / colomn, exit sub
If MSFlexGrid1.MouseRow <= MSFlexGrid1.FixedRows - 1 Or MSFlexGrid1.MouseCol <= MSFlexGrid1.FixedCols - 1 Then Exit Sub
Select Case Button
Case vbKeyRButton 'Right Mouse button down
SetEquation 'Gosub to set cell selection and tool tip
Case vbKeyLButton 'Left Mouse button down
'Set cell selection without showing ToolTip
LastSelected_Row = MSFlexGrid1.Row
LastSelected_Col = MSFlexGrid1.Col
'Set the Highlight colors
MSFlexGrid1.CellForeColor = vbYellow
MSFlexGrid1.CellBackColor = vbBlue
End Select
End If
DoEvents
End Sub
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'See where the mouse is, and if not in the "current" cell,
'change the "current" cell data and remove the last tool tip
Label_Info.Visible = True
'Set some form display values
txtMouse_X = Str(x)
txtMouse_Y = Str(y)
If MSFlexGrid1.MouseCol <> Current_Col Or MSFlexGrid1.MouseRow <> Current_Row Then
'Save the cell that you came from
Last_Row = Current_Row
Last_Col = Current_Col
'Now save the current Row,Column that the mouse is over
Current_Row = MSFlexGrid1.MouseRow
Current_Col = MSFlexGrid1.MouseCol
'Turn off redraw property to stop "flicker" of selected cell
MSFlexGrid1.Redraw = False
'Save Last selected Row/Column
LastSelected_Row = MSFlexGrid1.Row
LastSelected_Col = MSFlexGrid1.Col
'Reselect the row,column
MSFlexGrid1.Row = Last_Row
MSFlexGrid1.Col = Last_Col
DoEvents
'If row or column is the fixed row/column, do not change color
If Last_Row <> MSFlexGrid1.FixedRows - 1 And Last_Col <> MSFlexGrid1.FixedCols - 1 Then
'Reset cell colors
MSFlexGrid1.CellForeColor = vbBlack
MSFlexGrid1.CellBackColor = vbWhite
End If
'Now reselect the cell the mouse is over
MSFlexGrid1.Row = Current_Row
MSFlexGrid1.Col = Current_Col
DoEvents
'If row or column is the fixed row/column, do not change color
If Current_Row <> MSFlexGrid1.FixedRows - 1 And Current_Col <> MSFlexGrid1.FixedCols - 1 Then
'Change the current cells "Highlighted" colors
'If mouse over current selected cell, usr these colors
If MSFlexGrid1.Row = LastSelected_Row And MSFlexGrid1.Col = LastSelected_Col Then
MSFlexGrid1.CellForeColor = vbYellow
MSFlexGrid1.CellBackColor = vbBlue
Else
'If mouse over any other call, use tese colors
MSFlexGrid1.CellForeColor = vbWhite
MSFlexGrid1.CellBackColor = vbRed
End If
End If
'Now restore the REAL last Mouse or cursor selected column
MSFlexGrid1.Row = LastSelected_Row
MSFlexGrid1.Col = LastSelected_Col
DoEvents
'Kill any tool tips
MSFlexGrid1_Tip.Remove
'Turn redraw property "on" to refelect color changes
MSFlexGrid1.Redraw = True
DoEvents
'Set some form display values
txtMouseRowCol.Text = "第 " & Str(MSFlexGrid1.MouseRow) & "行 / 第 " & Str(MSFlexGrid1.MouseCol) & "列"
txtTipState.Text = "禁止"
Picture1.Visible = False
End If
End Sub
Private Sub MSFlexGrid1_RowColChange()
'Disable (remove) Tool Tip if selected cell has changed
If MSFlexGrid1.Redraw = True Then
'Remove any active tool tip
MSFlexGrid1_Tip.Remove
'Set some form display values
txtTipState.Text = "禁止"
Picture1.Visible = False
txtSelRowCol.Text = "第 " & Str(MSFlexGrid1.Row) & "行 / 第 " & Str(MSFlexGrid1.Col) & "列"
MSFlexGrid1_Click
End If
End Sub
Private Sub Timer1_Timer()
'Timer for "Mouse_Over" event, see modMouseOver
'I know it's a bit of a cheat using a timer,
'but just for checking for the "Mouse Over" on just one control
'I didn't see the need for subclassing or hooks just for this
'type project. See modMouseOver for code.
On Error Resume Next
If Not IsMouseOver(MSFlexGrid1) And MouseIn_grid = True Then
txtMouse_X.Text = ""
txtMouse_Y.Text = ""
txtMouseRowCol.Text = ""
MSFlexGrid1_Tip.Remove
txtTipState.Text = "禁止"
Picture1.Visible = False
Label_Info.Visible = False
MSFlexGrid1.Redraw = False
MSFlexGrid1.Row = Current_Row
MSFlexGrid1.Col = Current_Col
DoEvents
'If row or column is the fixed row/column, do not change color
If Current_Row <> MSFlexGrid1.FixedRows - 1 And Current_Col <> MSFlexGrid1.FixedCols - 1 Then
'Reset cell colors
MSFlexGrid1.CellForeColor = vbBlack
MSFlexGrid1.CellBackColor = vbWhite
End If
MSFlexGrid1.Row = LastSelected_Row
MSFlexGrid1.Col = LastSelected_Col
DoEvents
Current_Row = 0
Current_Col = 0
MSFlexGrid1.Redraw = True
End If
'If mouse enters the control without focus, set the focus to the control
If IsMouseOver(MSFlexGrid1) And MouseIn_grid = False Then
MSFlexGrid1.SetFocus
End If
MouseIn_grid = IsMouseOver(MSFlexGrid1)
End Sub
Private Sub SetEquation()
'Get the data to for an equation. Format x * y = z
'and setup Tool Tip to show for that cell
MSFlexGrid1.Redraw = False
MSFlexGrid1.Col = MSFlexGrid1.MouseCol
MSFlexGrid1.Row = MSFlexGrid1.MouseRow
MSFlexGrid1_Click
Result = MSFlexGrid1.Text
MSFlexGrid1.Col = 0
Operator1 = MSFlexGrid1.Text
MSFlexGrid1.Col = MSFlexGrid1.MouseCol
MSFlexGrid1.Row = 0
Operator2 = MSFlexGrid1.Text
MSFlexGrid1.Row = MSFlexGrid1.MouseRow
'Build the Balloon Tool Tip object
TipText = "当前乘式为 " & Operator1 & " X " & Operator2 & " = " & Result
MSFlexGrid1_Tip.CreateBalloon MSFlexGrid1, _
TipText, _
"乘法表", 1
'Set some form infomation
txtTipState.Text = "允许"
Picture1.Visible = True
'Set the Highlight colors
MSFlexGrid1.CellForeColor = vbYellow
MSFlexGrid1.CellBackColor = vbBlue
'CC_Comment Out (2/6/2005):
' 'Set current cell as last selected
' LastSelected_Row = MSFlexGrid1.Row
' LastSelected_Col = MSFlexGrid1.Col
'End CC_Comment Out
MSFlexGrid1.Row = LastSelected_Row
MSFlexGrid1.Col = LastSelected_Col
MSFlexGrid1.Redraw = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -