从非活动表单发送命令到 showDialogue 表单

发布于 2024-10-16 08:14:19 字数 183 浏览 0 评论 0原文

我想从另一个非活动表单发送密钥到显示对话表单。参见图片

在此处输入图像描述

表单 a 正在显示对话。后面是另一种形式,具有定制的键盘和数字键盘。 我只是根据这些按钮点击发送密钥。 我怎么可能从键盘发送按键来显示对话形式。

I want to send keys to a show dialogue form from another inactive form.See the picture

enter image description here

Form a is showing dialogue.Behind is another form which has a customized keyboard and numpad.
I simply send keys against these button clicks.
How is it possible that I can send keys from keyboard to show dialogue form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2024-10-23 08:14:19

你问的基本上是不可能的。一旦您了解了模态对话框的工作原理(使用 ShowDialog 方法显示的表单是模态的),您就会明白其中的原因。当您想要强制用户与该对话框进行交互时,可以使用模式对话框。它通过禁用这些窗口来阻止它们与应用程序中的任何其他窗口交互。它们变得不受鼠标点击的影响,不接收键盘输入,并且无法接收焦点。当你尝试时,Windows 会向你发出蜂鸣声,并闪烁模式对话框的标题栏,这是摇头说“不,不,不”的不微妙方式。

因此,这里发生的情况是,当您使用 ShowDialog 方法将“存款”表单显示为模式对话框时,应用程序中的所有其他窗口都将被禁用。在您的特定情况下,这意味着包含屏幕键盘的窗口也被禁用,并且无法接收鼠标单击事件。这就是为什么当您尝试单击其“键”(按钮)时没有任何反应的原因。

最简单的解决方法(正如我在评论中建议的那样)是使用 Show 方法将“存款”表单显示为模式对话框。与模式对话框不同,这不会禁用应用程序中的其他窗口,从而允许用户立即与所有窗口进行交互。单击另一个窗口会将焦点设置到该窗口并允许其处理输入事件。但您说这对您来说不起作用,因为您希望“存款”表单禁用您的窗口上的每个控件,但不是屏幕键盘上的控件。

当然,一开始我说“不可能”是撒谎的。我的意思是,这非常棘手,并且需要您解决标准的 Windows 交互模型。一些想法
你可能会想到如何去做:

  1. 你可以使用所有最新版本的 Windows 中包含的屏幕键盘实用程序。微软已经为此目的提供了一个程序。您不必构建和维护自己的,它已经包含所有必要的逻辑,以防止它在用户单击其“键”之一时窃取焦点,并且由于它不是您程序的一部分,因此它当您使用 ShowDialog 方法将表单显示为模式时,不会被禁用。要查看它,请转到“开始”->“运行并输入 osk

    例如,在 Windows 7 中,它看起来像这样:

    Windows 7 中的屏幕键盘

  2. 如果您坚持使用您自己的、定制设计的屏幕键盘,您必须将其显示为模式对话框的子窗口。也就是说,您的应用程序像往常一样从其主窗体开始。然后,当您使用 ShowDialog 方法将“存款”表单显示为模式对话框时,主表单将被禁用。在“存款”表单中,您可以使用-模态 Show 方法显示屏幕键盘表单。主窗体仍然处于禁用状态,因为它显示了一个模式对话框(“存款”窗体)。但“存款”表单并未被禁用,因为它显示的是一个模式对话框(您的屏幕键盘)。

What you're asking is essentially impossible. Once you understand how modal dialogs work (forms that are shown using the ShowDialog method are modal), you will understand why. A modal dialog is used when you want to force the user to interact only with that dialog. It prevents them from interacting with any other windows in your application by disabling those windows. They become impervious to mouse clicks, don't receive keyboard input, and can't receive the focus. Windows beeps at you and flashes the title bar of the modal dialog when you try, it's non-subtle way of shaking its head and saying "no, no, no".

So what's going on here is that when you show your "Deposits" form as a modal dialog using the ShowDialog method, all of the other windows in your application are disabled. In your particular case, that means the window that contains your on-screen keyboard is disabled, too, and can't receive mouse click events. That's why nothing is happening when you try to click on its "keys" (buttons).

The easiest workaround (as I suggested in a comment) is to show your "Deposits" form as a non-modal dialog using the Show method instead. Unlike a modal dialog, this will not disable other windows in your application, allowing the user to interact with all of them at once. Clicking on another window will set focus to that window and allow it to process input events. But you say this isn't workable for you, because you want the "Deposits" form to disable every control on your main window, but not your on-screen keyboard.

Of course, I lied at the beginning when I said it was "impossible". What I meant is that is that it's very tricky, and will require you to work around the standard Windows interactivity model. A couple of ideas
on how you might go about doing that spring to mind:

  1. You could use the On-Screen Keyboard utility that is included with all recent versions of Windows. Microsoft already provides a program for this purpose. You don't have to build and maintain your own, it already includes all the necessary logic to prevent it from stealing the focus when the user clicks on one of its "keys", and since it isn't part of your program, it won't be disabled when you show forms as modal using the ShowDialog method. To check it out, go to Start -> Run and type osk.

    For example, in Windows 7 it looks something like this:

    On-Screen Keyboard in Windows 7

  2. If you insist on using your own, custom-designed on-screen keyboard, you will have to show it as a child window of your modal dialog. That is, your application starts with its main form, per usual. Then, when you show the "Deposits" form as a modal dialog using the ShowDialog method, the main form gets disabled. From the "Deposits" form, you can then show the on-screen keyboard form using the non-modal Show method. The main form is still disabled, because it's showing a modal dialog (the "Deposits" form). But the "Deposits" form is not disabled, because it's showing a non-modal dialog (your on-screen keyboard).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文