Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have several text boxes on a form and i want a keyboard in my windows application by which a user could type in different textboxes.
i made key board using many button and every button behind this code.
C#
Button b = sender as Button;
       Search_Form.tb.Text += b.Text;

but this is working for only one textbox.
a genral keyboard i require by which a user could type in any textbox
Posted
Updated 27-Oct-13 7:29am
v2
Comments
Mahesh Bailwal 26-Oct-13 14:41pm    
what is "Search_Form.tb", is it one of the text boxes on the form?
Muhamad Faizan Khan 26-Oct-13 23:18pm    
yes
BillWoodruff 26-Oct-13 23:24pm    
Are you saying that you want to direct the result of the end-user clicking your keyboard "buttons" to one of several TextBoxes ?

If that's correct, what determines which TextBox the keyboard clicks send characters to ?
Muhamad Faizan Khan 26-Oct-13 23:28pm    
exactly. user click on textbox then he open keyboard or already open keyboard should be type in focus keyboard
Sergey Alexandrovich Kryukov 27-Oct-13 1:54am    
You need to tag the UI library/framework or application type you are using. Most likely, this is System.Windows.Forms. Or anything else?
Please tag the question accordingly.
—SA

Following steps may resolve your problem

1. Declare a textbox in your form as given below
private System.Windows.Forms.TextBox txtCurrentBox;


2. Add Enter event handler for every text box like below
private void textBox1_Enter(object sender, EventArgs e)
   {
       txtCurrentBox = sender as TextBox;
   }


3. Add new function like given below.
private void TypeToTextBox(object sender)
   {
       Button b = sender as Button;
       if (txtCurrentBox != null)
       {
           txtCurrentBox.Text += b.Text;
       }
   }


4. On click of every keyboard button call this function as given below
private void btn_b_Click(object sender, EventArgs e)
      {
          TypeToTextBox(sender);
      }
 
Share this answer
 
Comments
BillWoodruff 27-Oct-13 4:53am    
+5 Good answer, Mahesh. You could simplify things a bit by setting all the TextBoxes to use the same 'Enter EventHandler, and all the Buttons to use the same 'Click EventHandler. By setting the value of your variable that holds a TextBox in the Form_Load EventHandler, you can eliminate the need for checking for 'null.

Not clear in this case if the TextBoxes are meant to be read-only, or, if not read-only, what is supposed to happen (if anything) if the user enters content, or changes content in the TextBoxes.
Mahesh Bailwal 27-Oct-13 5:26am    
Yes you are very much right about it. Thanks :)
Muhamad Faizan Khan 27-Oct-13 13:03pm    
nice. But what should i need to do if my textboxes inside of Gridview. how can i find Gridview's textbox enter event???? and my new texbox do appear on a button click event.
BillWoodruff 27-Oct-13 21:48pm    
If you are using a modified GridView with a sub-classed Column of TextBoxes, I think you can set all the TextBoxes to use the same TextChanged EventHandler, and use the strategy Mahesh suggests above.
With virtual keyboard and several keyboard inputs, there are some difficulties. One of them is that, in general case, an input need keyboard focus, but clicking on it grabs the focus and deactivates the virtual keyboard. Here is my resolution: you can make the keyboard window not focusable but with "always on top" window style:
Application focus getting and losing[^].

If you do this, you can use such keyboard universally, and not only on Forms application (note that, say, WPF, in applications, controls are not windowed controls, so you cannot send Windows message to them (not the best idea anyway), but you can type in anything with your virtual keyboard written in System.Windows.Forms). And to type not only into the controls of the same application.

See also my past answers on the topic:
Creating a Virtual Keyboard[^],
Programming on BACKSPACE button[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900