问题,我的第二种形式是关闭 [英] Problem, my second form is closing

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

问题描述

嘿,伙计们!我有一个问题..当我打开我的第二个表单,我可以在form1中的列表框中添加东西时,第二个表单就像这样关闭:



1.打开第二种形式

2.添加我要添加的内容

3.关闭...



我不喜欢我希望form2关闭,我希望它保持不变,所以我可以同时添加更多项目到列表框。我怎么能这样做?

Hey again guys! I have a problem.. When i open my second form where i can add things to a listbox in form1 the second form is closing like this:

1. Open the second form
2. Add what i want to add
3. Close...

I don''t want the form2 to close i want it to stay so i can add more items at same time to the listbox. How can i do this?

推荐答案

好的,不要关闭它。这通常是关闭框的以太删除,或通过捕获关闭表单和取消其处理的事件来完成,通常隐藏表单。为此,您需要处理事件 System.Windows.Forms.Form.FormClosing

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing .aspx [ ^ ]。



或者,通过覆盖虚方法 System.Windows.Forms.Form.OnFormClosing

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing.aspx [ ^ ]。



在这些情况下,请检查 System.Windows.Forms.FormClosingEventArgs.CloseReason 。如果它是 System.Windows.Forms.CloseReason.UserClosing ,请将 System.Windows.Forms.FormClosingEventArgs.Cancel 设置为假。请参阅:

http:// msdn .microsoft.com / zh-cn / library / system.windows.forms.form.formclosing.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs.aspx [< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs.aspxtarget =_ blanktitle =New Window> ^ ],

http://msdn.microsoft.com /en-us/library/system.windows.forms.formclosingeventargs.closereason.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.closereason.aspx [ ^ ]。



我认为现在应该很清楚。



但是,我不建议使用多种形式(我不算数)模态形式,但即使模态形式的数量应该非常有限)。还有更多其他问题,忘记了用户的便利性。只使用一个主窗体更好,就像Visual Studio一样。您可以将内容放在许多可以显示和隐藏的面板,各种手风琴式面板,对接面板(高级设计,如Visual Studio)或非常简单明了的方法中,而不是表格, TabControl



-SA
OK, don''t close it then. This is normally done be ether removing of the close box, or by capturing the event of closing the form and cancellation of its handling, usually hiding the form instead. To do so, you need to handle the event System.Windows.Forms.Form.FormClosing:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx[^].

Or, alternatively, by overriding of the virtual method System.Windows.Forms.Form.OnFormClosing:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing.aspx[^].

In these cases, fist check up System.Windows.Forms.FormClosingEventArgs.CloseReason. If it is System.Windows.Forms.CloseReason.UserClosing, set System.Windows.Forms.FormClosingEventArgs.Cancel to false. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs.closereason.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.closereason.aspx[^].

I think is should be quite clear now.

However, I would not recommend using multiple form (I don''t count modal forms, but even the number of modal forms should be very limited). There are more other problems, forget user convenience. It''s much better to live with only one, main form, pretty much like Visual Studio does. Instead of forms, you can put content on many panels which you can show and hide, all kind of accordion-style panels, docking panels (advanced design, like in Visual Studio) or, very simple and clear approach, TabControl.

—SA


这篇关于问题,我的第二种形式是关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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