未成功将活动表单置于前面或重新显示隐藏表单 [英] Not successful to bring a active form to front or re-show a hidden form

查看:73
本文介绍了未成功将活动表单置于前面或重新显示隐藏表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,有两种形式。从第一个(或主要)表单,我使用下面的代码显示第二个:

 formViewData frmViewData =  new  formViewData(iCase,m_dt [iCase],m_dt [iCase]); 
frmViewData.Show();
frmViewData.BringToFront();



但是,第二个仍然落后于第一个。什么是解决它的正确方法?

除此之外我还尝试了另一种方法,即隐藏第一种形式

  .Hide();  //  或this.Visible = false;  



但是,当我关闭第二个表单时,我无法使用该代码打开第一个表单。

 View.uxMain.Show();  //  错误:非静态字段,方法或属性需要对象引用...  



解决这个问题的正确方法是什么?谢谢,如果你能分享你的经验。



我尝试过:



未成功将活动表单置于最前面或重新显示隐藏表单

解决方案

显示旨在显示一个新的,独立的表单,并让现有的一个像以前一样继续 - 这意味着当它具有用户焦点时,它不能落后第二个表格或用户无法看到他在做什么!



如果你要做的是显示一个控制的表单,就像MessageBox一样 - 在MessageBox关闭之前有效地禁用父表单 - 那很简单:

 formViewData frmViewData =  new  formViewData(iCase,m_dt [iCase],m_dt [iCase]); 
frmViewData.ShowDialog();

主表单上的处理将停止,直到表单关闭。

如果你想隐藏你的主表单,而另一个是显示,然后:

 formViewData frmViewData =  new  formViewData(iCase,m_dt [iCase],m_dt [ ICASE]); 
隐藏();
frmViewData.ShowDialog();
Show();

或处理第二个FormClosed事件:

 formViewData frmViewData =  new  formViewData(iCase,m_dt [iCase],m_dt [iCase]); 
frmViewData.FormClosed + = frmViewData_FormClosed;
隐藏();
frmViewData.Show();



然后在处理程序中:

  void  frmViewData_FormClosed( object  sender,FormClosedEventArgs e)
{
Show();
}



您可以通过将第二种形式设置为始终位于顶部来实现 - 但这通常比它的价值更麻烦,因为它的系统范围不是应用程序具体


In my project, there are 2 forms. From the 1st (or main) form, I use the code below to show the 2nd one:

formViewData frmViewData = new formViewData(iCase, m_dt[iCase], m_dt[iCase]);
frmViewData.Show();
frmViewData.BringToFront();


However, the 2nd one is still behind the 1st one. What's the proper way to solve it?
Besides I also tried another way, namely hide the 1st form by

this.Hide();  // or this.Visible = false;


However, when I close the 2nd form, I could not use the code to open the 1st form.

View.uxMain.Show();  // Error: An object reference is required for the non-static field, method, or properties ...


What's the proper way to solve this problem? Thanks if you can share your experience.

What I have tried:

Not successful to bring a active form to front or re-show a hidden form

解决方案

Show is intended to display a new, independant form, and let the existing one continue as before - which means that when it has the user focus, it can't be "behind" the second form or the user can't see what he is doing!.

If what you are trying to do is show a form that "takes control" in the same way that a MessageBox does - effectively disabling the "parent" form until the MessageBox is closed - then that's simple:

formViewData frmViewData = new formViewData(iCase, m_dt[iCase], m_dt[iCase]);
frmViewData.ShowDialog();

Processing on your main form will stop until the form is closed.
If you want to hide your main form while the other is displayed, then either:

formViewData frmViewData = new formViewData(iCase, m_dt[iCase], m_dt[iCase]);
Hide();
frmViewData.ShowDialog();
Show();

Or handle the second form FormClosed event:

formViewData frmViewData = new formViewData(iCase, m_dt[iCase], m_dt[iCase]);
frmViewData.FormClosed += frmViewData_FormClosed;
Hide();
frmViewData.Show();


Then in the handler:

void frmViewData_FormClosed(object sender, FormClosedEventArgs e)
    {
    Show();
    }


You can do it by setting the second form to "always on top" - but that's generally more trouble than it's worth as it's system wide not application specific.


这篇关于未成功将活动表单置于前面或重新显示隐藏表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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