显示表格-等待表格关闭后再处理下一行 [英] Show form - wait for form to close before processing next line

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

问题描述



我正在使用VB2005.

我想在执行显示表单后停止父表单中的处理.当子窗体关闭时,控件将返回到父窗体,然后继续处理.

该怎么办呢?

谢谢

解决方案

打开新表单时,请使用ShowDialog()而不是Show(),您会如愿以偿.


<首先,没有父母和子女形式;有所有者和所有者的表格.如果您不知道这表示您不使用此关系,则应该使用.使所有非模态非主表单归主表单所有;这对于应用程序激活的完整性很重要(尝试使用激活,您会发现很大的不同).将System.Windows.Forms.Form.Owner用于所有非主要形式;还对所有拥有的表单使用Form.ShowInTaskbar = false -非常有用.

现在,您要暂停的处理是什么?什么是表格已执行"?没有这样的概念.显示了吗?模态与否?至于控制权"又回到了 parent [owner-SA]表单",它是独立发生的,但是您应该使用所有权关系,请参见前面的段落.最后一个问题是:您是否想要在再次关闭后显示拥有的表单吗?是的,您需要隐藏它而不是关闭并在需要时再次显示.另一种选择是通过Form.ShowDialog以模态方式使用它.
隐藏技术如下:

 使用 System.Windows.Forms;

//  ... 

受保护的 覆盖  void  OnClosing(FormClosingEventArgs e) {
   如果(例如,CloseReason == CloseReason.UserClosing){
       .Hide();
      e.Cancel =  true ;
   }
} 



—SA


其他没有人提到的是,如果您使用ShowDialog显示一个Form,则必须在处理完该Form实例后调用Dispose .


Hi,

I''m using VB 2005.

I want processing in the parent form to halt after a show form is executed. When the child form is closed then control returns back to the parent form and processing continues.

How can this be done?

Thanks

解决方案

When you open a new form, use ShowDialog() instead of Show() and you will get your wish.


First, there are not parent and child forms; there are owned and owner''s form. If you don''t know that it means you don''t use this relationship, but you should. Make all non-modal non-main form owned by the main one; it is important for application activation integrity (try it with activation and you will see the great difference). Use System.Windows.Forms.Form.Owner for all non-main forms; also use Form.ShowInTaskbar = false for all owned forms — very useful.

Now, what is processing you want to halt? What is "form is executed"? There is no such notion. Shown? Modal or not? As to "control" returns back to the parent [owner — SA] form" — it happens by itself, but you should use ownership relationship, see the previous paragraphs. Final question is: do you want to show the owned form after closing ever again? Is so, you need to hide it instead of closing and show again when you need it. Another option is using it in a modal way, via Form.ShowDialog.

Hiding technique looks like this:

using System.Windows.Forms;

//...

protected override void OnClosing(FormClosingEventArgs e) {
   if (e.CloseReason == CloseReason.UserClosing) {
      this.Hide();
      e.Cancel = true;
   }
}



—SA


Something else noone mentioned is if you show a Form with ShowDialog, you MUST also call Dispose on that form instance when you''re done with it.


这篇关于显示表格-等待表格关闭后再处理下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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