MDI帮助 [英] MDI Help
问题描述
我正在尝试创建一个MDI应用程序。我打开窗户OK
(MDI儿童)。但我不认为我这样做是正确的。
基本上,我在主表单(父母)上声明表格。
frm1 f1;
frm2 f2;
等
每张表格一张。
然后,当我打开表格时,我就这么做:
if(f1!= null)
f1 = new frm1 ;
....
f1.Show();
f1.BringToFront();
但是,如果我关闭表单,并尝试打开...它会中断...我没有
代码的结束,所以它似乎认为即使f1是
关闭......它不是空的......
我应该如何关闭表格?或者,有更好的方法来做这个吗?
$ div class =h2_lin>解决方案
即使f1关闭了...... '不是空的......
是的 - 什么都不会自动清除字段,所以它*不是* null(也不是
是否收集,因为该领域保持在范围内。
两个解决方案;第一个是挂钩进入Form'的FromCosed事件
并将该字段设置为null - 但这有点杂乱无章,因为它
使得有一个表格的倍数棘手。我个人忘记了字段中的
,只需枚举MdiChildren寻找可能的
表格 - 如果你发现这样,把它带到前面,否则产卵一个新的
并将其作为孩子添加。这样,你不必担心
字段(没有)。你可以做一下show existing /
新表格< x>简单地使用泛型 - 类似于(记事本代码 - 不是
测试):
void ShowForm< T>()其中T:Form,new(){
foreach(MdiChildren中的表格儿童){
如果(孩子是T){
child.BringToFront();
返回;
}
//找不到
T newForm = new T();
newForm.MdiParent = this; //或者......但是......我不记得......
newForm.Show();
newForm.BringToFront();
}
}
Marc
忘记添加 - 然后你只需要打电话:
ShowForm< Form1>();
或者其他什么,其中Form1是Form类型的类名。
12月30日15:43,Marc Gravell< marc.grav ... @ gmail.comwrote:
忘了添加 - 那么你只需要打电话:
ShowForm< Form1>();
或者其他什么,其中Form1是班级 - 表单类型的名称。
太棒了!
我会给这个打击。我在这方面相当新手。感谢
帮助,Marc。
I am trying to create an MDI Application. I am opening the windows OK
(MDI Children). But I don''t think I am doing it correctly.
Basically, I declare the forms on the main form (Parent).
frm1 f1;
frm2 f2;
etc
One for each form.
Then, when I open the form, I just do:
if (f1 != null)
f1 = new frm1;
....
f1.Show();
f1.BringToFront();
However, if I close the form, and try open... it breaks... I have no
code for the close, so it seems to think that even though f1 is
closed... it''s not null...
How should I be closing forms? Or, is there a better way to be doing
this?
even though f1 is closed... it''s not null...
Yes - nothing will automatically clear fields, so it *isn''t* null (nor
is it collected, since the field keeps it in-scope).
Two solutions; the first is the hook into the Form''s FromCosed event
and set the field to null - but this is a little scrappy since it
makes having multiples of a form tricky. Personally I''d forget about
the fields, and simply enumerate the MdiChildren looking for a likely
form - if you find such, bring it to the front, else spawn a new one
and add it as a child. This way, you don''t have to worry about the
fields (there aren''t any). And you can probably do the "show existing/
new form<x>" simply with generics - something like (notepad code - not
tested):
void ShowForm<T>() where T : Form, new() {
foreach(Form child in MdiChildren) {
if(child is T) {
child.BringToFront();
return;
}
// not found
T newForm = new T();
newForm.MdiParent = this; // or however... I can''t remember...
newForm.Show();
newForm.BringToFront();
}
}
Marc
Forgot to add - then you would just call:
ShowForm<Form1>();
or whatever, where Form1 is the class-name of a type of Form.
On 30 Dec, 15:43, Marc Gravell <marc.grav...@gmail.comwrote:Forgot to add - then you would just call:
ShowForm<Form1>();
or whatever, where Form1 is the class-name of a type of Form.Fantastic!
I''ll give this a bash. I''m quite a novice at this. Thanks for the
help, Marc.
这篇关于MDI帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!