A recent project to do a touch screen application, because there is no keyboard, all need to use the soft keyboard, although the system can call the soft keyboard, but the system software disk cannot be fixed position, that is, each pop-up position is not fixed, and sometimes block the next text box to enter. Second, the program in the screen is displayed in full screen, the user can not quit the program, but after the system software disk can be easily shut down the program, or the computer shutdown restart. So just write your own keyboard program, because only one interface needs to be entered, all directly embed the keyboard into the form.
First look at the test
Here is a four text box can accept user input, when the user clicks on an input box, you can click the button to enter the corresponding number, when the click on the grid to delete the input content. Also, if the user finds that the input is incorrect
Can be added or deleted on the basis of the input, at the specified location.
The specific code is as follows:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace keyboard{public partial class Form1:form {TextBox currenttextbox; int currentpos; Public Form1 () {InitializeComponent (); foreach (Control ctl in Controls) {if (CTL. GetType (). Equals (typeof (TextBox))) ctl. LostFocus + = new EventHandler (ctl_lostfocus); else if (ctl. Name = = "Btnkeyboardclear") ctl. Click + = new EventHandler (Ctl_clearclick); else if (ctl. GetType (). Equals (typeof (Button)) && ctl. Name! = "btnsubmit") ctl. Click + = new EventHandler (Ctl_click); Else ctl. Enter + = new EventHandler (ctl_enter); }} void Ctl_clearclick (object sender, EventArgs e) {if (Currenttextbox! = null) {try {currenttextbox.text = Curr EntTextBox.Text.Remove (currentpos-1, 1); Currentpos-= ((Button) sender). Text.length; Currenttextbox.focus (); Currenttextbox.selectionstart = Currentpos + 1; currenttextbox.selectionlength = 0; } catch {MessageBox.Show ("Please remove from the correct location! "); }} else return; } void Ctl_enter (object sender, EventArgs e) {currenttextbox = null; } void Ctl_click (object sender, EventArgs e) {if (Currenttextbox! = null) { Currenttextbox.text = CurrentTextBox.Text.Insert (Currentpos, ((Button) sender). Text); Currentpos + = ((Button) sender). Text.length; Currenttextbox.focus (); Currenttextbox.selectionstart = Currentpos; currenttextbox.selectionlength = 0; } else return; } void Ctl_lostfocus (object sender, EventArgs e) {currenttextbox = (TextBox) sender; Currentpos = Currenttextbox.selectionstart; } }}
WinForm Digital Soft Keyboard