[英]How to minimize a winforms app when there is at least one modal window opened
I have two form classes (Form1 and Form2) in a Winforms App. 我在Winforms应用程序中有两个表单类(Form1和Form2)。
Form1 is like this: Form1是这样的:
Form2 is like this (ShowInTaskbar = false): Form2是这样的(ShowInTaskbar = false):
And this code on Form1: 这个代码在Form1上:
Form2 someForm = new Form2();
private void btOpenAnotherWindow_Click(object sender, EventArgs e)
{
if (someForm.ShowDialog(this) == DialogResult.OK)
MessageBox.Show("OK!!!");
else
MessageBox.Show("Not OK.");
}
That is, a window with a button which opens modally another windows when clicked, and waits for the user to close the second window (by clicking the "OK" or "Cancel" button). 也就是说,一个带有按钮的窗口,在单击时以模态方式打开另一个窗口,并等待用户关闭第二个窗口(通过单击“确定”或“取消”按钮)。 And depending how it was closed, do alternating actions (represented here by the MessageBox.Show() calls).
并根据它是如何关闭的,执行交替操作(此处由MessageBox.Show()调用表示)。
I need: 我需要:
the above example fails in two ways: 以上示例以两种方式失败:
Before Minimize button is clicked: 单击最小化按钮之前:
After: 后:
Note: 注意:
Form2 is a full blown window (not a dialog window per se) and I need the user to interact with it only until it is closed and I also need the user to be able to miminize the whole app in case he needs it. Form2是一个完整的窗口(本身不是一个对话框窗口),我需要用户与它进行交互,直到它关闭,我还需要用户能够在需要时将整个应用程序缩小。
It is a shame I can't post here the real forms, It would be clearer than these mock-ups. 遗憾的是我无法在这里发布真实的形式,这将比这些模型更清晰。
I need a solution that works with many levels of modal windows (not only two as this example shows). 我需要一个适用于多级模态窗口的解决方案(不仅如本例所示,还有两个)。 Any suggestions?
有什么建议?
I may need a little more information about what you're trying to do here. 我可能需要更多关于你在这里尝试做什么的信息。 I have a simple form (Form1) with a button on it, which calls this code:
我有一个简单的表单(Form1),上面有一个按钮,调用此代码:
private void button1_Click(object sender, EventArgs e)
{
Form1 form2 = new Form1();
form2.ShowDialog();
}
When I click the button, I get a second instance of the same form, but it's modal. 当我单击按钮时,我得到了相同表单的第二个实例,但它是模态的。 I still have the option to minimize this second modal form (I obviously can't interact with the first form), and when I do minimize the second form it does minimize the entire application (both forms).
我仍然可以选择最小化第二个模态形式(我显然不能与第一个形式交互),当我最小化第二个形式时,它确实最小化了整个应用程序(两种形式)。 Now obviously you're asking the question, so I don't think I'm understanding you.
现在显然你在问这个问题,所以我不认为我理解你。 =) What about this scenario do you wish to change?
=)你希望改变这种情况怎么样?
There is probably some way to hack this functionality using API calls, but I would probably suggest doing some type of overlay with a control inside your main form rather than an actual window. 可能有一些方法可以使用API调用破解这个功能,但我可能会建议在主窗体中使用控件而不是实际窗口进行某种类型的叠加。 This would allow you to make it "modal" and still have the ability to minimize/resize the main window.
这将允许您使其“模态”并仍然能够最小化/调整主窗口的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.