Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

Modal mode to show forms that allows non-modal forms

$
0
0
This is a simple function that can be used as a replacement to show forms "modally" but still allow to show non-modal forms:

In a module:

Code:

Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)

Public Sub ShowModal(nForm As Form, Optional OwnerForm)
    Dim ColF As Collection
    Dim ColE As Collection
    Dim f As Form
    Dim c As Long
   
    Set ColF = New Collection
    Set ColE = New Collection
    For Each f In Forms
        If Not f Is nForm Then
            ColF.Add f
            ColE.Add f.Enabled
            f.Enabled = False
        End If
    Next
    nForm.Show , IIf(IsMissing(OwnerForm), Screen.ActiveForm, OwnerForm)
    Do While IsFormLoaded(nForm)
        DoEvents
        Sleep 1
    Loop
    For c = 1 To ColF.Count
        ColF(c).Enabled = ColE(c)
    Next
End Sub

Private Function IsFormLoaded(nForm As Form) As Boolean
    Dim f As Form
   
    For Each f In Forms
        If f Is nForm Then
            IsFormLoaded = True
            Exit Function
        End If
    Next
End Function

Usage:

Code:

ShowModal Form2

Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>