WinForm Digital Soft Keyboard

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.