问题与消息框

问题与消息框

问题描述:

我有一个问题,用于模拟的MessageBox。问题与消息框

这里的情况是,

  • 从形式提供给用户选择XX
  • 消息框出现
  • 用户打开embebed软件键盘(内置于一体,从设备)
  • 用户关闭键盘
  • MessageBox失去焦点(怎么样,它被认为是模态!),主窗体显示在前台
  • 应用程序块,因为用户现在不能关闭MessageBox。

这是MessageBox的代码片段。

MessageBox.Show("message", "caption", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, 
            MessageBoxDefaultButton.Button1); 

有关如何解决这个问题的任何想法?

+0

还有其他有趣的因素吗?看起来你应该“只是工作”。如果你创建一个新窗体并在这个新窗体上执行'ShowModal()',会发生什么?你会看到相同的行为吗? – Nate 2010-09-17 18:59:26

在调用MessageBox.Show(IWin32Window参数,通常只传入“this”)时,需要包含对父窗体的引用。我相信这是你想要使用的过载 - 见下:

MessageBox.Show Method (IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton) 

Here is a link to the Microsoft documentation.

享受!

+0

不幸的是,紧凑的框架不支持这个 – MerickOWA 2010-09-17 19:21:58

+2

不 - 不支持 - CF不支持这一点,即使它没有解决问题(请参阅我的答案) – ctacke 2010-09-17 21:39:25

这实际上是在Windows CE下有些预期的行为(我不是说它是正确的,只是预期)。

当您单击桌面角落的SIP按钮时,整个应用程序失去焦点并将焦点传递给任务栏。您可以通过点击应用程序的任务栏按钮来看到类似的“奇怪” - 即使您应该只将焦点发送给已运行的应用程序,但MessageBox将失去焦点。

你可以看到,它不是一个CF错误改变你的观察MessageBox的调用就像这样:

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的CE 5.0设备上进行了测试,并且MessageBox在CF和P/Invoke版本中都保持最佳状态。

您是否可以用一个非常基本的应用程序(即只有一个窗体,一个按钮)重现此行为?如果是这样,那听起来像是一个平台问题。关于使用CE的一点要记住的是,由于OEM对操作系统的实际操作有很大的控制权,所以你绝不能排除行为的平台错误。

MessageBox.Show("Please insert Correct Username and Password.", "Login Error", 
       MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
this.Focus(); 

它是一个简单的解决方案。无需运行任何JavaScript或其他C#代码。