确定表单是否已打开。 [英] Determine if a Form is already open.

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

问题描述

如果表格已经打开,我怎么能通过代码告诉你。

每次我的表格加载时我都会运行一些初始化代码,但是如果

表单已经打开并隐藏我不希望初始化代码为
运行。因此,我只是想取消隐藏表格。


我的想法是eveyrtime我去加载一个表格我可以扫描我所有的

打开表格项目并确定我是否已经准备好开始支付
负载是否开放。


所以,这是一个两部分问题。 />

1.如何判断表格是否打开?

2.如何循环打开所有打开的表格?


谢谢。

How can I tell via code if a Form is already open.

Each time my forms load I have some initialization code that runs, but if
the form is already open and hidden I don''t want that initialization code to
run. Thus, I just want to unhide the form.

My thought is eveyrtime I go to load a form I could scan through all the
open forms in my project and determine whether the one I''m getting ready to
load is open or not.

So, this is a two part question.

1. How can I tell if a form is open?
2. How can I loop through all open forms?

Thank you.

推荐答案

创建一个名为modForms的朋友模块。

添加一个名为Forms的朋友哈希表。< br $>

朋友模块modForms

朋友表格为新Hashtable()

结束模块


在每个表单的Form_Load事件中...


Me.Name =" FormName"

modForms.Forms.Add(Me.Name,Me )


这将在当前项目的

中所有文件都可访问的中心位置添加引用。


当你想要时o打开一个表格...


Dim F作为表格

如果不是IsNothing(modForms.Forms(" FormName"))那么

F = modForms.Forms(" FormName")

如果F.Visible = False那么

F.Show()

else

F.BringToFront()

结束如果

否则

F =新FormNameObject()

F.Show()

结束如果


为了让生活更轻松,请使用表格的类名称为Name属性


注意:此代码仅在不存在
的情况下才创建表单的新实例。对象变量仅用作对表单的引用。


如果initialation代码在New sub或Form_Load中,它只会在使用后运行

这段代码。


" Greg"写道:
Create a friend module called modForms.
Add a friend hashtable called Forms.

Friend Module modForms
Friend Forms As New Hashtable()
End Module

In the Form_Load event for each form...

Me.Name = "FormName"
modForms.Forms.Add(Me.Name, Me)

This will add a reference in a central location accessible to all files in
the current project.

When you want to open a form...

Dim F As Form
If Not IsNothing(modForms.Forms("FormName")) Then
F = modForms.Forms("FormName")
If F.Visible = False Then
F.Show()
else
F.BringToFront()
End If
Else
F = New FormNameObject()
F.Show()
End If

To make life easier, use the class name of the form for the Name property

NOTE: This code only only creates a new instance of the form if it does not
yet exist. The object variables serve only as references to the form.

If the initialation code is in the New sub, or Form_Load, it will only run
once using this code.

"Greg" wrote:

如果表格已经打开,我如何通过代码告诉。


每次我的表格加载我都有一些初始化代码运行,但是如果

表单已经打开并隐藏我不想要初始化代码来运行
。因此,我只是想取消隐藏表格。


我的想法是eveyrtime我去加载一个表格我可以扫描我所有的

打开表格项目并确定我是否已经准备好开始支付
负载是否开放。


所以,这是一个两部分问题。 />

1.如何判断表格是否打开?

2.如何循环打开所有打开的表格?


谢谢。
How can I tell via code if a Form is already open.

Each time my forms load I have some initialization code that runs, but if
the form is already open and hidden I don''t want that initialization code to
run. Thus, I just want to unhide the form.

My thought is eveyrtime I go to load a form I could scan through all the
open forms in my project and determine whether the one I''m getting ready to
load is open or not.

So, this is a two part question.

1. How can I tell if a form is open?
2. How can I loop through all open forms?

Thank you.


Greg,


为什么要打开所有表单,这不是一种假脱机性能和< br $> b $ b内存?

我的想法肯定不是OOP,更多是使用Net的Modulair编程。


Cor

Greg,

Why you want all forms open, is this not a kind of spooiling performance and
memory?

In my idea for sure not OOP, more a kind of Modulair programming using Net.

Cor


如果您决定使用我建议的代码,您可能需要添加代码以删除

哈希表引用形式为'结束事件。


Private Sub Form1_Closing(ByVal sender As Object,_

ByVal e As System.ComponentModel.CancelEventArgs)Handles MyBase.Closing

modForms.Forms.Remove(" Form1")

End Sub

" Greg"写道:
If you decide to use my suggested code, you might want to add code to remove
the hashtable reference to the form in the form''s closing event.

Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
modForms.Forms.Remove("Form1")
End Sub
"Greg" wrote:

如果表格已经打开,我如何通过代码告诉。


每次我的表格加载我都有一些初始化代码运行,但是如果

表单已经打开并隐藏我不想要初始化代码来运行
。因此,我只是想取消隐藏表格。


我的想法是eveyrtime我去加载一个表格我可以扫描我所有的

打开表格项目并确定我是否已经准备好开始支付
负载是否开放。


所以,这是一个两部分问题。 />

1.如何判断表格是否打开?

2.如何循环打开所有打开的表格?


谢谢。
How can I tell via code if a Form is already open.

Each time my forms load I have some initialization code that runs, but if
the form is already open and hidden I don''t want that initialization code to
run. Thus, I just want to unhide the form.

My thought is eveyrtime I go to load a form I could scan through all the
open forms in my project and determine whether the one I''m getting ready to
load is open or not.

So, this is a two part question.

1. How can I tell if a form is open?
2. How can I loop through all open forms?

Thank you.


这篇关于确定表单是否已打开。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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