为什么我不能把C#windows应用到前面 [英] Why I can not bring to front, C# windows aplication

查看:57
本文介绍了为什么我不能把C#windows应用到前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在C#Windows窗体项目中尝试将打开的表单置于顶部,从工具条菜单打开,发出蜂鸣声并锁定。

有人可以帮我解决这个问题吗。

David。

Hello I try in C# Windows Form Project to bring opened form to top, Opened from Tool Strip Menu, beep and lock.
Can somebody help me with this problem.
David.

private void openFlToolStripMenuItem_Click(object sender, EventArgs e)
{
  Application.OpenForms["MainForm"].BringToFront();
}

private void positionsBalanceToolStripMenuItem_Click(object sender, EventArgs e)
{
  Positions_Balance p_b = new Positions_Balance();
  p_b.ShowDialog();
  p_b.BringToFront();
}

private void ordersToolStripMenuItem_Click(object sender, EventArgs e)
{
  Orders o = new Orders();
  o.ShowDialog();
  o.BringToFront();
}

private void symbolLookupToolStripMenuItem_Click(object sender, EventArgs e)
{
  Symbol_Lookup s_l = new Symbol_Lookup();
  s_l.ShowDialog();
  s_l.BringToFront();
}





我的尝试:



我试过,我找到了,但它不是正确的C#源代码。



What I have tried:

I tried , what I find , but it's not the right C# source code.

推荐答案

当你在表单上调用ShowDialog时,它会创建什么被称为模态对话框 - 这意味着它会覆盖应用程序中的所有现有表单,并且在新表单关闭之前它们不会响应用户输入。在此之前,您不能将任何其他表单设置为前表单,因为这是将接收键盘输入的表单。



从您显示的示例代码中,你似乎已经有了模态对话 - 他们不会;当你在它们上面调用BringToFront时,它们确实作为表格存在,因为它们必须被关闭才能在ShowDialog调用之后将控制权返回给原始代码。
When you call ShowDialog on a form, it creates what is called a Modal Dialog - which means that it overrides all existing forms in the application, and they do not respond to user input until the new form has been closed. Until then, you cannot set any other form as the "front" form because that is the one that will receive the keyboard input.

From the sample code you show, you seem to have Modal Dialogs there allready - and they dont; really exist as forms by the time you call BringToFront on them as they have to be closed in order to return control to the original code after the ShowDialog call.


这篇关于为什么我不能把C#windows应用到前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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