Sending command to showDialogue Form from inactive form
I want to send keys to a show dialogue form from another inactive form.See the picture
Form a is showing dialo开发者_运维技巧gue.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.
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:
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 typeosk
.For example, in Windows 7 it looks something like this:
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-modalShow
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).
精彩评论