Keyboard on the screen in WinForms

爱⌒轻易说出口 提交于 2019-12-22 13:49:16

问题


I have developed a Windows Forms application which is used on a touchscreen computer. Is it possible to display a keyboard when the user clicks on an input box (textbox)? And how can i do that ?


回答1:


Are you aware Windows has an on screen keyboard?

In Windows 7 it is All Programs > Accesseries > Ease Of Access > On Screen Keyboard.

You can write you own if you want, but I use the Windows one all the time when I do not feel like picking up the keyboard.

You can create a shortcut to it:

The location is %windir%\system32\osk.exe

So to launch it, in the TextBox_Click event (or whatever event you want to fire)

// Should work, I have not tested it. System.Diagnostics.Process.Start("c:\Windows\System32\osk.exe");

Just an update: On my machine at work I got an error trying to run that code (I built it as a test) and I had to copy the osk.exe to another directory and then launch it and it worked.

    /// <summary>
    /// Test to show launching on screen board (osk.exe).
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void textBox1_Click(object sender, EventArgs e)
    {
        try
        {
            Process.Start(@"c:\Temp\OSK.exe");
        }
        catch (Exception error)
        {
            string err = error.ToString();
        }
    }

And this code worked.




回答2:


Your example show error for me:

"Could not start On-Screen Keyboard"

I found this code which work fine without any errors:

static void StartOSK()
{
  string windir = Environment.GetEnvironmentVariable("WINDIR");
  string osk = null;

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "sysnative"), "osk.exe");
    if (!File.Exists(osk))
      osk = null;
  }

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "system32"), "osk.exe");
    if (!File.Exists(osk))
    {
      osk = null;
    }
  }

  if (osk == null)
    osk = "osk.exe";

  Process.Start(osk);
}



回答3:


I think you have to create a new form to ccreate the keyboard and launch this form in textbox click




回答4:


I think you can use. System.Diagnostics.process.start

   System.Diagnostics.Process.Start("osk.exe");


来源:https://stackoverflow.com/questions/9298515/keyboard-on-the-screen-in-winforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!