Pergunta

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.

Foi útil?

Solução

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();

}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top