关闭所有表格 [英] Closing all forms

查看:61
本文介绍了关闭所有表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个漂亮的例程每次调用
时逐个关闭一个表单。但是,我需要隐藏它们而不是关闭它们。

有没有办法改变代码?我认为这与

这一行有关...

PostMessage(i,CInt(& H10),vbNullString,vbNullString)
< br $>
谢谢


k

Public Sub closeallforms()

Dim objType As Type()=

Reflection.Assembly.GetExecutingAssembly.GetTypes()

Dim x As Integer,i As Integer

试试

For x = LBound(objType)到UBound(objType)

如果不是objType(x).Name = Me.Name然后''///确保

你不卸载这个形式呢。

i = FindWindow(vbNullString,objType(x).Name)

PostMessage(i,CInt(& H10),vbNullString,

vbNullString)

结束如果

下一页

Catch ex As Exception

MessageBox.Show(" Oops ,发生以下错误:"&

ex.Message)

最后

''MyBase.Close()'// /现在所有其他形式都是

关闭,卸载这个。

结束尝试
End Sub

I found this nifty routine that closes a form one by one every time it
is called. However, I need to hide them instead of closing them. Is
there a way to alter the code? I assume it has something to do with
this line here...
PostMessage(i, CInt(&H10), vbNullString, vbNullString)

Thanks

k
Public Sub closeallforms()
Dim objType As Type() =
Reflection.Assembly.GetExecutingAssembly.GetTypes( )
Dim x As Integer, i As Integer
Try
For x = LBound(objType) To UBound(objType)
If Not objType(x).Name = Me.Name Then ''/// make sure
you dont unload this form yet.
i = FindWindow(vbNullString, objType(x).Name)
PostMessage(i, CInt(&H10), vbNullString,
vbNullString)
End If
Next
Catch ex As Exception
MessageBox.Show("Oops, the following error occured:" &
ex.Message)
Finally
''MyBase.Close() ''/// now that all the other forms are
closed , unload this one.
End Try
End Sub

推荐答案

< kr ******* @ yahoo.co.ukschrieb
<kr*******@yahoo.co.ukschrieb

我发现这个漂亮的例程每次都会逐个关闭一个表单

它被调用。但是,我需要隐藏它们而不是关闭它们。

有没有办法改变代码?我假设它有事可做

这条线在这里...


PostMessage(i,CInt(& H10),vbNullString,vbNullString)
I found this nifty routine that closes a form one by one every time
it is called. However, I need to hide them instead of closing them.
Is there a way to alter the code? I assume it has something to do
with this line here...
PostMessage(i, CInt(&H10), vbNullString, vbNullString)



我甚至没有引用这个真正的_awesome_代码。


很抱歉没有回答你的其他问题。我认为你需要在写更多行代码之前先了解一些OOP基础并了解可变范围



$ b $嗯,我从哪里开始......?对不起,如果你已经知道了以下的一些




首先,你有哪个VB版本?在VB 2008(或者可能是2005年)中,OpenForms属性有

(请使用符号搜索来查找它)。但是,

我从来没有用过它,因为我从来不需要这样的属性。

但是,当然,你可以使用OpenForms属性。 br />

其次,UI线程(用户界面)有一个消息循环。操作系统是基于消息的
消息。消息循环(参见F1)是一个循环,它处理操作系统放入队列的所有

消息。在框架中,消息循环

在Application.Run中(参见对象浏览器)。有超载的

版本:一个没有args,一个有一个arg期望一个Form对象。

一个w / o args运行直到线程调用Application.ExitThread。另一个

一个人做的工作直到通过的表格已经关闭。


3rd,application framework。如果启用,您可以选择启动

表格。还有一个选项可以说直到所有表格已经关闭。 (或类似的)。 VB将创建一个不可见的Sub Main - UI

线程的主程序,每个线程都有 - 在项目属性中指示的行为类似于

。如果禁用应用程序框架

,您可以设置自己的Sub Main,例如,

在显示任何表单或其他任何内容之前打开数据库连接。


现在,您选择哪个版本?为什么你需要关闭所有

表格,正如主题所说的那样?或者,也许你在任务栏中有额外的NotifyIcon

?如果你有一个启动表格(因此上面的说明是

),那就关闭那个。如果您有自己的Sub Main,请告诉我们

它是什么样的。


为了能够回答您的其他问题,请描述方案

尽可能详细说明。我的意思是,哪个表单从何处打开,哪个
需要关闭另一个?你有MDI From吗?目前,我

只能给出多用途的答案:如果你需要一个

对象的引用,你必须让它可用。怎么做,取决于

的情况。


(sry有很多东西需要阅读;我总是喜欢写一篇关于我最喜欢的文章。 >
主题。;-))

Armin

I do not even quote this really _awesome_ code.

Sorry for not answering your other question, yet. I thought that you
should really get into some OOP basics and learn about variable scope
before writing more lines of code.

Well, where do I start...? Sorry, if you already know some of the
following things:

First, which VB version do you have? in VB 2008 (or maybe 2005) there is
the OpenForms property (please use symbol search to find it). However,
I''ve never used it because I''ve never needed a property like that.
However, of course, you can use the OpenForms property.

Second, a UI thread (user interface) has a message loop. The OS is
message based. The message loop (see F1) is a loop that processes all
messages put into a queue by the OS. In the Framework, the message loop
is inside Application.Run (see object browser). There are overloaded
versions: One has no args, one has one arg expecting a Form object. The
one w/o args runs til the thread calls Application.ExitThread. The other
one does it''s job til the passed Form has been closed.

3rd, "application framework". If enabled, you can choose the startup
Form. There is an additional option that says "til all Forms have been
closed" (or similar). VB will create an invisible Sub Main - the UI
thread''s main procedure that every thread has - that behaves like
instructed in the project''s properties. If the "application framework"
is disabled, you can set your own Sub Main where you can, for example,
open a database connnection before showing any form or whatever.

Now, which version did you choose? Why do you need to "close all
Forms", as the subject says? Or, maybe you have an additional NotifyIcon
in the task bar? If you have a startup Form (therefore the explanation
above), just close that one. If you have your own Sub Main, show us how
it looks like.

To be able to answer your other question, please describe the scenario
as detailled as possible. I mean, which Form opens from where and which
one needs to close another one? Do you have an MDI From? Currently, I
can only give the multi-purpose answer: If you need a reference to an
object, you have to make it available. How to do it, depends on the
situation.

(sry for a lot to read; I always like writing about one of my favorite
topics. ;-) )
Armin


5月3日晚上9:17, Armin Zingler < az.nos ... @ freenet.dewrote:
On May 3, 9:17 pm, "Armin Zingler" <az.nos...@freenet.dewrote:

< kronec ... @ yahoo.co.ukschrieb
<kronec...@yahoo.co.ukschrieb

我发现这个漂亮的例程每次都会逐个关闭一个表单

它被调用。但是,我需要隐藏它们而不是关闭它们。

有没有办法改变代码?我假设它有事要做

这条线在这里...
I found this nifty routine that closes a form one by one every time
it is called. However, I need to hide them instead of closing them.
Is there a way to alter the code? I assume it has something to do
with this line here...


PostMessage(i,CInt(&) H10),vbNullString,vbNullString)
PostMessage(i, CInt(&H10), vbNullString, vbNullString)



我甚至没有引用这个真正的_awesome_代码。


很抱歉没有回答你的问题还有其他问题。我认为你需要在写更多行代码之前先了解一些OOP基础并了解可变范围



$ b $嗯,我从哪里开始......?对不起,如果你已经知道了以下的一些




首先,你有哪个VB版本?在VB 2008(或者可能是2005年)中,OpenForms属性有

(请使用符号搜索来查找它)。但是,

我从来没有用过它,因为我从来不需要这样的属性。

但是,当然,你可以使用OpenForms属性。 br />

其次,UI线程(用户界面)有一个消息循环。操作系统是基于消息的
消息。消息循环(参见F1)是一个循环,它处理操作系统放入队列的所有

消息。在框架中,消息循环

在Application.Run中(参见对象浏览器)。有超载的

版本:一个没有args,一个有一个arg期望一个Form对象。

一个w / o args运行直到线程调用Application.ExitThread。另一个

一个人做的工作直到通过的表格已经关闭。


3rd,application framework。如果启用,您可以选择启动

表格。还有一个选项可以说直到所有表格已经关闭。 (或类似的)。 VB将创建一个不可见的Sub Main - UI

线程的主程序,每个线程都有 - 在项目属性中指示的行为类似于

。如果禁用应用程序框架

,您可以设置自己的Sub Main,例如,

在显示任何表单或其他任何内容之前打开数据库连接。


现在,您选择哪个版本?为什么你需要关闭所有

表格,正如主题所说的那样?或者,也许你在任务栏中有额外的NotifyIcon

?如果你有一个启动表格(因此上面的说明是

),那就关闭那个。如果您有自己的Sub Main,请告诉我们

它是什么样的。


为了能够回答您的其他问题,请描述方案

尽可能详细说明。我的意思是,哪个表单从何处打开,哪个
需要关闭另一个?你有MDI From吗?目前,我

只能给出多用途的答案:如果你需要一个

对象的引用,你必须让它可用。怎么做,取决于

的情况。


(sry有很多东西需要阅读;我总是喜欢写一篇关于我最喜欢的文章。 >
主题。;-)

Armin


I do not even quote this really _awesome_ code.

Sorry for not answering your other question, yet. I thought that you
should really get into some OOP basics and learn about variable scope
before writing more lines of code.

Well, where do I start...? Sorry, if you already know some of the
following things:

First, which VB version do you have? in VB 2008 (or maybe 2005) there is
the OpenForms property (please use symbol search to find it). However,
I''ve never used it because I''ve never needed a property like that.
However, of course, you can use the OpenForms property.

Second, a UI thread (user interface) has a message loop. The OS is
message based. The message loop (see F1) is a loop that processes all
messages put into a queue by the OS. In the Framework, the message loop
is inside Application.Run (see object browser). There are overloaded
versions: One has no args, one has one arg expecting a Form object. The
one w/o args runs til the thread calls Application.ExitThread. The other
one does it''s job til the passed Form has been closed.

3rd, "application framework". If enabled, you can choose the startup
Form. There is an additional option that says "til all Forms have been
closed" (or similar). VB will create an invisible Sub Main - the UI
thread''s main procedure that every thread has - that behaves like
instructed in the project''s properties. If the "application framework"
is disabled, you can set your own Sub Main where you can, for example,
open a database connnection before showing any form or whatever.

Now, which version did you choose? Why do you need to "close all
Forms", as the subject says? Or, maybe you have an additional NotifyIcon
in the task bar? If you have a startup Form (therefore the explanation
above), just close that one. If you have your own Sub Main, show us how
it looks like.

To be able to answer your other question, please describe the scenario
as detailled as possible. I mean, which Form opens from where and which
one needs to close another one? Do you have an MDI From? Currently, I
can only give the multi-purpose answer: If you need a reference to an
object, you have to make it available. How to do it, depends on the
situation.

(sry for a lot to read; I always like writing about one of my favorite
topics. ;-) )

Armin



我有一个使用Windows媒体播放器的应用程序一个单独的

表格+其他零碎也在不同的表格上。我可以使用上面的代码关闭它们

但是由于某些原因我关闭了窗口

媒体播放器它将无法再次打开,除非我重新启动程序。 />
因此隐藏它是一件更好的事情,隐藏而不是

关闭会对我有用。

但是,我的一个表格不会隐藏使用通常的formx.hide()

方法(它也不会关闭)。那么如何通过

一个隐藏所有表格...

K.

I have an application which uses Windows media player on a separate
form + other bits and pieces also on separate forms. I can close them
all using the above code but for some reason when I close windows
media player it will not open again unless I re-start the program.
Therefore hiding it is a better thing to do so hiding rather than
closing will do for me.
However, one of my forms will not hide using the usual formx.hide( )
method (it won''t close either). So how to hide all the forms one by
one...
K.


< kr * ****** @yahoo.co.ukschrieb
<kr*******@yahoo.co.ukschrieb

>

我有一个单独使用Windows媒体播放器的应用程序

表格+其他零碎也在不同的表格上。我可以关闭

他们都使用上面的代码,但出于某种原因当我关闭

windows media player时它不会再打开,除非我重新启动

计划。因此隐藏它是一件更好的事情,这样做可以隐藏

而不是关闭会对我有用。

但是,我的一个表单不会隐藏使用通常的formx.hide ()

方法(它也不会关闭)。那么如何通过

一个隐藏所有表单...
>
I have an application which uses Windows media player on a separate
form + other bits and pieces also on separate forms. I can close
them all using the above code but for some reason when I close
windows media player it will not open again unless I re-start the
program. Therefore hiding it is a better thing to do so hiding
rather than closing will do for me.
However, one of my forms will not hide using the usual formx.hide( )
method (it won''t close either). So how to hide all the forms one by
one...



什么是项目的启动对象?你从哪里打开WMP表格

和其他人?你想从哪里关闭它们?你有MDI

表吗?我确实理解你想要隐藏一个表格(或一些表格),但表格之间的

关系对我来说仍然不清楚。哪种表格

"生活总是?您是否指定表格作为其他人的所有者?

有模态表格(与问题有关)?

Armin

What''s the project''s startup object? From where do you open the WMP Form
and the others? From where do you want to close them? Do you have an MDI
Form? I do understand that you want to hide a Form (or some), but the
relations between the Forms is still not clear to me. Which of the Forms
"lives" always? Do you specify a Form as the Owner of other(s)? Are
there modal Forms (related to the problem)?
Armin


这篇关于关闭所有表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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