【问题标题】:Visual Basic 6 :: Unload Dynamically Created FormVisual Basic 6 :: 卸载动态创建的表单
【发布时间】:2017-09-19 19:24:55
【问题描述】:

我正在努力解决这个问题,但没有任何运气:(

这是我的代码:

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

我想在 3 秒后自动关闭新创建的表单。

【问题讨论】:

  • 你的意思是Unload Me,还是Unload frm
  • 你的设计是不好的做法。您不应该向用户显示一条消息,然后在几秒钟后将其删除,因为它只会让用户感到困惑,他们会认为出现了问题。更改设计,您的问题就会消失。

标签: forms timer vb6 sleep


【解决方案1】:

以模态模式打开的窗口等待用户输入,所以后面的语句

frm.Show vbModal

不会执行。

.

您有两种解决方案:

a) 移除 vbModal

b) 在 myForm 上添加 Timer 并将 Interval 设置为 1000(平均 1 秒),然后在 Timer 事件中添加此代码:

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

最后,你应该使用

Unload frm

因为卸载我是错误的。

【讨论】:

    【解决方案2】:

    您可以像这样使用计时器,一旦达到 3 秒 (3000),它将关闭表单并打开另一个表单。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多