Visual Basic 6 ::卸载动态创建的窗体 [英] Visual Basic 6 :: Unload Dynamically Created Form

查看:212
本文介绍了Visual Basic 6 ::卸载动态创建的窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:



pre $ Option Explicit

Private Declare Sub Sleep Libkernel32(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秒后自动关闭新创建的窗体。

解决方案

Windows以模态模式等待为用户输入,所以在

之后的语句

  frm.Show vbModal 

不会执行。





您有两种解决方案:

a)删除vbModal b / b> b)在 myForm 上添加Timer并将Interval设置为1000(意味着1秒),接下来将此代码添加到Timer中事件:

pre $私人子Timer1_Timer()
静态秒作为整数
秒=秒+ 1
如果sec> = 3那么
Timer1.Enabled = False
Unload Me
End If
End Sub

最后,您应该使用

 卸载frm 

因为Unload Me错误。


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.

解决方案

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.

这篇关于Visual Basic 6 ::卸载动态创建的窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆