通过OpenFileDialog和SaveFileDialog使用自定义屏幕键盘形式 [英] Use custom on-screen keyboard form with OpenFileDialog and SaveFileDialog

查看:115
本文介绍了通过OpenFileDialog和SaveFileDialog使用自定义屏幕键盘形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为.NET Windows Forms应用程序的一部分,我们有一个自定义的屏幕键盘(OSK)表单.该键盘对于在DataGridView和其他一些文本框中输入数据很有用.我们希望能够使用它在OpenFileDialogSaveFileDialog中输入文件名.

We have a custom on-screen keyboard (OSK) form as part of our .NET Windows Forms Application. This keyboard is useful to enter data into a DataGridView and some other textboxes. We want to be able to use it to enter a file name into an OpenFileDialog or SaveFileDialog.

但是,当任一对话框出现时,包含OSK的表单将停止响应输入.我尝试创建一个新的Form用作OSK的所有者.我使用新表格并调用keyboard.Show(owner).这仍然不能防止OpenFileDialogSaveFileDialog在其ShowDialog方法中时无法使用键盘.

However, when either Dialog shows up, the form containing the OSK stops responding to input. I tried creating a new Form that is used as the OSK's owner. I use the new form and call keyboard.Show(owner). This still doesn't prevent the keyboard from being unable to be used while an OpenFileDialog or SaveFileDialog is in their ShowDialog method.

我们如何在OpenFileDialogSaveFileDialog顶部使用屏幕键盘形式,而不必将键盘托管在单独的进程中?

How can we use an on-screen keyboard form on top of an OpenFileDialog or SaveFileDialog without having the keyboard be hosted in a separate process?

推荐答案

好吧,在另一个进程中运行OSK窗口 是个好主意.您可以通过运行Windows提供的osk.exe免费获得它.从技术上讲,您可以在另一个STA线程上运行它,但这是一种相当先进的技术,SystemEvents类可能以多种方式严重破坏您的生活.

Well, running the OSK window in another process is a fine idea. You get it for free by running osk.exe, provided by Windows. You could technically run it another STA thread but that's a fairly advanced technique, too many ways where the SystemEvents class can seriously ruin your life.

但是您可以用一小段代码解决问题,只需要在对话框显示后立即重新启用OSK窗口即可.使用BeginInvoke()方法完美完成:

But you can solve the problem with a sliver of code, you just need to re-enable the OSK window right after the dialog is displayed. Elegantly done with the BeginInvoke() method:

    private void OpenButton_Click(object sender, EventArgs e) {
        this.BeginInvoke(new Action(() => EnableWindow(osk.Handle, true)));
        if (openFileDialog1.ShowDialog(this) == DialogResult.OK) {
            // etc...
        }
    }

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool EnableWindow(IntPtr hWnd, bool enable);

假设osk变量存储对OSK表单的引用.

With the assumption that the osk variable stores a reference to your OSK form.

这篇关于通过OpenFileDialog和SaveFileDialog使用自定义屏幕键盘形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆