我遇到了一个MessageBox的问题,它是用来做模态的。
情况就是这样,
下面是MessageBox的代码片段。
MessageBox.Show("message", "caption", MessageBoxButtons.OK, MessageBoxIcon.Asterisk,
MessageBoxDefaultButton.Button1);对如何解决这个问题有什么想法吗?
发布于 2010-09-17 21:37:43
这实际上是Windows下的一些预期行为(我并不是说它是正确的,只是预期的)。
当你点击桌面角落的SIP按钮时,你的整个应用程序会失去焦点,焦点会传递给任务栏。通过单击应用程序的Task按钮,您可以看到类似的"wierdness“-- MessageBox将失去焦点,尽管您应该将焦点发送到已经运行的应用程序。
通过如下更改MessageBox调用,您可以看到它不是CF错误:
private void button1_Click(object sender, EventArgs e)
{
//MessageBox.Show("message", "caption", MessageBoxButtons.OK,
// MessageBoxIcon.Asterisk,
// MessageBoxDefaultButton.Button1);
MessageBoxCE(this.Handle, "message", "caption", 0);
}
// renamed to not collide with the Windows.Forms MessageBox class
[DllImport("coredll", EntryPoint="MessageBox")]
private static extern int MessageBoxCE(IntPtr hWnd, string lpText,
string lpCaption, int Type);你也会有同样的行为。
有一件事是没有预料到的,那就是父表单出现在MessageBox之上。我刚刚在我的桌面上的一个基于ARM的CE5.0设备上进行了测试,MessageBox在CF和P/Invoke版本中都保持在顶部。
你能用一个非常基本的应用程序(也就是一个表单,一个按钮)复制这种行为吗?如果是这样的话,这听起来就像一个平台问题。使用CE时要记住的一点是,由于OEM对操作系统的实际实现方式有很大的控制,因此您永远不能排除平台错误的行为。
发布于 2010-09-17 19:10:56
在调用MessageBox.Show时,需要包含对父表单的引用( IWin32Window参数,通常只是传入"this")。我相信这是你想要使用的过载-见下文:
MessageBox.Show Method (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)下面是指向Microsoft文档的链接。
享受吧!
发布于 2012-05-21 08:01:08
MessageBox.Show("Please insert Correct Username and Password.", "Login Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Focus();这是一个简单的解决方案。不需要运行任何JavaScript或其他C#代码。
https://stackoverflow.com/questions/3738115
复制相似问题