user3252014
user3252014

Reputation: 665

How do I make the virtual keyboard enter text into a textbox in WinForms application?

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.

Upvotes: 0

Views: 5737

Answers (1)

Mark Hall
Mark Hall

Reputation: 54562

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

}

Upvotes: 3

Related Questions