如何强制unload 窗体

hzcao 2004-01-16 03:10:01
如果在其他事件中卸载该窗体,我只要Unload Me就可以了。

可是我在Form_Load()事件中需要强制卸载窗体怎么办?

例如:

Private Sub Form_Load()
...
If Not DataLoad Then 卸载当前窗体
...
End Sub
...全文
40 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
leolan 2004-01-16
  • 打赏
  • 举报
回复
同樣也可以Unload Me呀~
davidlv 2004-01-16
  • 打赏
  • 举报
回复
或者是这样写,写在外面,不是写在form的load事件里

dim frm as form

set frm=form1
frm.show vbmodal
set frm=nothing




davidlv 2004-01-16
  • 打赏
  • 举报
回复
在unload里面写set form1=nothing
lxxldd 2004-01-16
  • 打赏
  • 举报
回复
在form_load 事件中
也可以用 unload me
lxxldd 2004-01-16
  • 打赏
  • 举报
回复

unload me
exit sub
zgq4u 2004-01-16
  • 打赏
  • 举报
回复
加载一个Timer控件,初始Enabled=False,Interval=1
在form_load中根据条件置Timer控件的Enabled为True
Private Sub Form_Load()
if ... then
Timer1.Enabled = True
else
......
end if
End Sub

Private Sub Timer1_Timer()
unload me
End Sub
mmcgzs 2004-01-16
  • 打赏
  • 举报
回复
为什么不这样写
If DataLoad Then me.hide
qingming81 2004-01-16
  • 打赏
  • 举报
回复
用如下的API

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Show the window
ShowWindow WinWnd, SW_SHOWNORMAL
'Create a buffer
lpClassName = Space(256)
'retrieve the class name
RetVal = GetClassName(WinWnd, lpClassName, 256)
'Show the classname
MsgBox "Classname: " + Left$(lpClassName, RetVal)
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
Maconel 2004-01-16
  • 打赏
  • 举报
回复
unload(form1)
LichKingSZ 2004-01-16
  • 打赏
  • 举报
回复
你为什么不在启动那个窗体的代码里这样写?:
If DataLoad Then 那个窗体.show
butianshi 2004-01-16
  • 打赏
  • 举报
回复
你为什么要这样做?

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧