Title | Make a window appear modal when it is not |
Keywords | form, modal, fake modal |
Categories | Controls, Tips and Tricks, Software Engineering |
|
|
In some cases, you may want to display a non-modal form while a modal form is visible. Unfortunately that's not possible. Instead you can use this trick to make a form seem modal when it isn't.
The following code displays the fake modal form.
|
|
Private Sub cmdShowFakeModalForm_Click()
Set frmFakeModal.ParentForm = Me
frmFakeModal.Show
End Sub
|
|
This code is in the fake modal form. When the form loads, it disables its parent form. When it unloads, it enables the parent form.
|
|
Public ParentForm As Form
Private Sub Form_Load()
If Not (ParentForm Is Nothing) Then ParentForm.Enabled _
= False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not (ParentForm Is Nothing) Then ParentForm.Enabled _
= True
Set ParentForm = Nothing
End Sub
|
|
Note that this only disables one parent form. If you want the fake form to seem modal with respect to more than one existing form, disable and enable them all.
|
|
|
|