formArray关闭/处置问题 [英] formArray close / dispose issue

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

问题描述

我给自己创造了一个问题,也许我的想法并不像我原来想象的那样明亮。

如果有人可以帮我弄清楚什么正确的思路应该是什么?或者是否有解决方案。


我创建了一个虚拟mdi应用程序。

在主窗体(frmMainScreen)中我创建了一个变量:

<写在记事本中以修剪所有内容>


公共共享frmFormsOpen()as frmMyTestForm


现在,在一个完全单独的子窗体中从主窗体中打开,我在

按钮上点击:


LengthOfGames =(frmMainScreen.frmFormsOpen.Length - 1)

ReDim Preserve frmMainScreen.frmFormsOpen(LengthOfGames)


frmMainScreen.frmFormsOpen (LengthOfGames)= new frmMyTestForm

frmMainScreen.frmFormsOpen(LengthOfGames).MdiParen t = Me.MdiParent

''请记住,这个表格也是ma的mdi孩子形式。

''设置我自己的房产供以后使用

frmMainScreen.frmFormsOpen(LengthOfGames).GameID = anIntegerValue


frmMainScreen.frmFormsOpen(LengthOfGames)。显示()


''作品很棒

所以在其他子表单表单的其他代码中我可以做这样的事情:


为每个SearchForm作为frmMyTestForm在

frmMainScreen.frmFormsOpen

如果SearchForm.GameID = mytestID那么''mytestID设置为a / $
来自别的东西

SearchForm.BringToFront()

退出

结束如果

下一页

我的问题是:


我在表格关闭时实际删除数组元素的位置。我不想让它留在阵列中。

我认为我不能在

frmMainScreen的_FormClosed中做到这一点。 frmFormsOpen(LengthOfGames)._ FormClo sed

因为我实际上还在表单中 - 所以我假设我不能

当我还在使用该对象时杀死该对象。

(我试图自杀自己)。


这是我自己创造的问题,我想知道是否有人可以

指出了我如何解决这个问题的正确方向。


谢谢,


Miro

解决方案

" Miro" < mi ** @beero.comschrieb


当表格

关闭时,我在哪里删除数组元素。我不希望它留在阵列中。



帮自己一个忙,并使用List(Of frmMyTestForm)代替数组。

(VB版本?)保险箱项目转移和重新整理。


我认为我不能在

frmMainScreen.frmFormsOpen(LengthOfGames)的_FormClosed中执行此操作._ FormClo sed

因为我实际上还在表单中 - 所以我假设我

当我还在使用对象时无法杀死对象。

(我试图从自己身上杀死自己)。



你不能通过删除一个引用来杀死任何东西。您可以安全地从FormClosed事件中的列表中删除

项。执行当前

方法的对象永远不会被销毁。

Armin


vb 2008


感谢你的帖子。

我的印象是 - 因为我在'br /'期间'坐'' >
_FormClose然后我无法从我的脚下移除我的物体。


我假设你的声明


>从不销毁执行当前方法的对象。



一旦我离开表单并且它关闭了 - 它将在

背景中销毁 - 我不需要运行其他任何东西?


我会谷歌并搜索列表使用列表而不是数组。


谢谢,

Miro


" ; Armin Zingler < az ******* @ freenet.dewrote in message

news:ub ************** @ TK2MSFTNGP02.phx.gbl ...


" Miro" < mi ** @ beero.comschrieb


>当表格关闭时,我在哪里删除数组元素。我不希望它留在阵列中。



帮自己一个忙,并使用List(Of frmMyTestForm)代替数组。

(VB版本?)保险箱项目转移和重新整理。


>我不认为我可以在
frmMainScreen.frmFormsOpen(LengthOfGames)的_FormClosed中执行此操作._ FormCl osed <因为我实际上仍处于形式本身 - 所以我假设我在使用对象时无法杀死对象。
(我试图自杀自己)。



你不能通过删除一个引用来杀死任何东西。您可以安全地从FormClosed事件的列表中删除

项目。执行

当前方法的对象永远不会被销毁。


Armin


"米罗" < mi ** @ beero.comschrieb


我假设您的声明


>> ;永远不会销毁执行当前方法的对象。



一旦我离开表单并且它关闭了 - 它将在

背景中销毁 - 我不需要运行其他任何东西?



是的,不需要其他任何东西。


我会google并搜索List使用列表而不是数组。



谷歌不需要 - 查看对象浏览器。这是

System.Collections.Generic.List(Of T)


另见:
http://msdn.microsoft.com/en-us/library/41107z8a.aspx

Armin


I have created myself an issue, and perhaps my idea wasn''t as bright as I
thought it was originally.
If someone can help me figure out what the correct train of thought should
be - or if there is a solution to this one.

I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>

Public Shared frmFormsOpen() As frmMyTestForm

Now, in a totally seperate sub form opend from the main form I do this on a
button click:

LengthOfGames = (frmMainScreen.frmFormsOpen.Length - 1)
ReDim Preserve frmMainScreen.frmFormsOpen(LengthOfGames)

frmMainScreen.frmFormsOpen(LengthOfGames) = New frmMyTestForm
frmMainScreen.frmFormsOpen(LengthOfGames).MdiParen t = Me.MdiParent
''Remember that this form is also an mdi child of the main form.
''Set my own property for later use
frmMainScreen.frmFormsOpen(LengthOfGames).GameID = anIntegerValue

frmMainScreen.frmFormsOpen(LengthOfGames).Show()

''Works Great
So in other code on other child forms forms I can do stuff like this:

For Each SearchForm As frmMyTestForm In
frmMainScreen.frmFormsOpen
If SearchForm.GameID = mytestID Then ''mytestID is set to a
value from something else
SearchForm.BringToFront()
Exit For
End If
Next
My problem is this:

where do i actually remove the array element when the form is closed. I do
not want it to stay in the array.
I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormClo sed
because I am actually in the form itself still - so I am assuming I cannot
kill the object when I am still using the object.
( im trying to kill myself from myself ).

That is my issue I have created myself and I was wondering if someone can
point me in the right direction on how to get around this issue.

Thanks,

Miro

解决方案

"Miro" <mi**@beero.comschrieb

where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.

I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormClo sed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don''t kill anything by removing one reference. You can safely remove the
item from the list in the FormClosed event. The object on which the current
method is executed is never destroyed.
Armin


Its vb 2008

Thank you for the post.
I was under the impression - since I am ''sitting'' in the object still during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement

>The object on which the current method is executed is never destroyed.

That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@freenet.dewrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...

"Miro" <mi**@beero.comschrieb

>where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.


Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.

>I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormCl osed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).


You don''t kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin


"Miro" <mi**@beero.comschrieb

Im assuming then by your statement

>>The object on which the current method is executed is never destroyed.

That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

Yes, nothing else is required.

I will google and search up "List" to use a list instead of an array.

Not required to google - look in the object browser. It''s
System.Collections.Generic.List(Of T)

see also:
http://msdn.microsoft.com/en-us/library/41107z8a.aspx
Armin


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

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