如何在.net c#或vb 控制台应用程序中显示消息框?就像是:
Console.WriteLine("Hello World");
MessageBox.Show("Hello World");
Run Code Online (Sandbox Code Playgroud)
要么
Console.WriteLine("Hello")
MsgBox("Hello")
Run Code Online (Sandbox Code Playgroud)
分别在c#和vb中.
可能吗?
我有一些MessageBox,我的代码如下:
MessageBox.Show(new Form(){TopMost=true, TopLevel=True}, "Message","Title", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
Run Code Online (Sandbox Code Playgroud)
为了更好的示例,我为FormClosing事件执行此操作:
private void Example_FormClosing(object sender, FormClosingEventArgs e){
MessageBox.Show(new Form(){TopMost=true, TopLevel=True}, "Really close?"," Program", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
Run Code Online (Sandbox Code Playgroud)
但是,几乎每次我都要在我的计算机上更改Window(比如返回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);
}
Run Code Online (Sandbox Code Playgroud)
我想把我的messageBox放在我的窗口前面而不必更改窗口来查看它,因为它就像在当前窗口后面.
你有想法解决这个问题吗?
如何使我的表单成为Windows XP中的"系统模式对话框"?
"关闭对话框",因此除了我在C#中的表单外,不能在Windows中进行任何操作.