I have a windows forms application containing a button and a textbox. At "button_click_event" this code is executed:

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

The keyboard shows, yet no text appears on the textbox as I type on said keyboard.

有帮助吗?

解决方案

What is happening is that the on screen keyboard is sending information to the Focused Control which in your case is the Button that initiated the Keyboard. Try setting focus to to your textbox after creating the keyboard.

private void button1_Click(object sender, EventArgs e)
{
    System.Diagnostics.Process.Start("osk.exe");
    //SetFocus to your TextBox here
    textBox1.Focus();
}

To close it do something like this

private void button2_Click(object sender, EventArgs e)
{
    var procs = Process.GetProcessesByName("osk");
    if (procs.Length != 0)
        procs[0].Kill();

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top