Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on multiple forms. I have a textBox, and when the user click on the textBox a new form is shown (which is actually my own developed on-screen keyboard). I want to type characters on the TextBox using my own on-screen keyboard. Right now, when the new form is displayed, the textBox becomes disabled. However, I'm using non-modal forms.
Posted
Comments
Member 11428137 14-Mar-15 6:01am    
How are you opening the new form? Can you show the code used to open it.
Member 11485559 14-Mar-15 6:07am    
private void textBox1_Click(object sender, EventArgs e)
{
subForm myNewForm = new subForm();
myNewForm.Show();
}
}

I want my keyboard to print characters in the TextBox just like it is printing in Notepad.
Member 11428137 14-Mar-15 6:10am    
Ok, and how does the sub form try to type to the textbox?
Member 11485559 14-Mar-15 6:12am    
That's where problem lies, I don't know any method to process inputs from child form to parent.
Member 11428137 14-Mar-15 6:17am    
In that case I suggest having a good read of OriginalGriffs linked article. It covers what you want to do quite nicely.

1 solution

If you are using myNewForm.ShowDialog() to display the form, then it will indeed disable the "parent" form - because ShowDialog opens a modal form. Use myNewForm.Show() instead, and it won't.

I would suggest that you also want to handle the new form FormClosing event in the parent form to prevent multiple copies being opened, and if you want the "keys" processed immediately, you should look at providing events from your keyboard form which the parent can handle and deal with appropriately. It's not difficult, see here: Transferring information between two forms, Part 2: Child to Parent[^]
 
Share this answer
 
Comments
Member 11485559 14-Mar-15 6:14am    
Thank you, I'm reading the article and would share the results soon.
Member 11485559 14-Mar-15 6:40am    
Sir, I couldn't understand how tbData is used in both parent and child. I have a textbox in parent, and in child I'm just pressing a key. Like, If I press "Q", then this Q is transferred to the parent and parent's Textbox then adds a "Q".
OriginalGriff 14-Mar-15 6:56am    
When you "detect" the keypress in the child, you work out the key value and raise an ever which the parent handles. It retrieves the keycode from the child, and passes that to the textbox. (I'd probably use a custom EventArgs to contain the code, to make suer they stay in order and none are lost if he types quickly).

The one thing you don't do is try to access the parent textbox from the child: that locks the child form to only ever working with one control on one form. Let the parent sort out what it wants to do with the input - that way you can use teh same child for multiple forms later on.

Make sense?
Member 11485559 14-Mar-15 7:02am    
Thank you so much for all your help. I am just being able to transfer characters from on-screen keyboard to the text.

Next step is to complete all the functionality of the keyboard and transfer alphabets to parent form. Thank you
OriginalGriff 14-Mar-15 7:05am    
You're welcome!

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