Visual Basic 6 :: Unload Dynamically Created Form

筅森魡賤 提交于 2020-01-15 08:47:06

问题


I'm trying hard to solve that issue without any luck :(

Here is my code :

Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private frm As Form

Public Sub GenerateForm()

    Set frm = New myForm

    With frm
        .Width = 4000
        .Height = 3000
        .Caption = "Message"
    End With

    frm.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2

    frm.Show vbModal

    Sleep 3000

    Unload Me
    Set frm = Nothing

End Sub

Private Sub Command1_Click()

    GenerateForm

End Sub

I want to close the newly created form automatically after 3 seconds.


回答1:


Windows opened in modal mode wait for user input, so the statements after

frm.Show vbModal

will not execute.

.

You have two solutions:

a) remove vbModal

b) add Timer on myForm and set Interval to 1000 (mean 1 second), next add this code in Timer event:

Private Sub Timer1_Timer()
    Static sec As Integer
    sec = sec + 1
    If sec >= 3 Then
        Timer1.Enabled = False
        Unload Me
    End If
End Sub

Last, you should use

Unload frm

since Unload Me is wrong.




回答2:


You could use the timer like this, once it reaches 3 seconds (3000) it will close the form and open another one.

Private Sub Timer1_Timer()
    If Timer1.Interval = 3000 Then
        frm_Menu.Show
        Unload frmSplash
        Timer1.Enabled = False
    End If
End Sub


来源:https://stackoverflow.com/questions/43565625/visual-basic-6-unload-dynamically-created-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!