【发布时间】:2013-04-09 11:49:53
【问题描述】:
我有一些 MessageBox,我这样编码:
MessageBox.Show(new Form(){TopMost=true, TopLevel=True}, "Message","Title", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
举个更好的例子,我为 FormClosing 事件这样做:
private void Example_FormClosing(object sender, FormClosingEventArgs e){
MessageBox.Show(new Form(){TopMost=true, TopLevel=True}, "Really close?"," Program", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
但是,几乎每次我必须在看到我的消息框之前更改我的计算机上的窗口(比如在 Visual Studio 上返回),它对用户不友好而且真的很烦人。
我确认我的主要表单不在 TopMost=true,我只尝试了 TopMost 或只尝试了 TopLevel,StartPosition=FormStartPosition.CenterScreen 但没有任何效果。
[更新]
我试过了:
private void Example_FormClosing(object sender, FormClosingEventArgs e){
MessageBox.Show(this.Owner, "Really close?"," Program", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
我想将我的 messageBox 放在窗口的前面,而不必更改窗口即可看到它,因为它就像在当前窗口的后面。
你有解决这个问题的想法吗?
【问题讨论】:
-
请说的更清楚些,不知道你在问什么。
-
你想达到什么目的?
-
需要先显示所有者。
-
能不能编译一下,TopLevel=True 是怎么工作的?
-
我想让我的消息框出现在所有其他当前打开的窗口的前面。我使用这些消息框来显示(例如)我所有的 datagridview 都保存在 db 上,或者要求用户在文本框中输入一些正确的格式,... 用户必须单击 Ok、Yes、No 或取消才能关闭这个消息框,继续工作
标签: c# messagebox topmost