到目前为止,我有一些代码允许用户点击 F1,它加载相同属性的新表单,然后隐藏他们第一个打开的表单,点击 F2,允许用户关闭新打开的表单并显示一个他们先开了。我想要一个限制,如果用户在打开 2 个相同表单的情况下按 F1,则只允许用户打开 1 个额外的表单,然后出现一个消息框,告诉他们先关闭第二个表单,否则允许打开它。
这是我到目前为止所拥有的。
Private Sub Form_Load()
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF1
'hides the current form
Me.Hide
'loads a new form with the same properties
Dim f As New Form1
Load f
'shows this new form
f.Show
'says that the second form is open
fOpen = True
Case vbKeyF2
'closes the second form
Unload Me
'says that the second form is closed
fOpen = False
'shows the first form you were on
Form1.Show
End Select
End Sub
Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)
'if your hitting "X" on second form then just close form2
If fOpen = False Then
Form1.Show
Else
'if your hitting "X" on main form close everything
Unload Me
End If
End Sub
可能类似于如果 fOpen = true 则不允许用户按 F1?不太确定,但我很接近。