Thursday, 14 February 2013

virtual key board in c#.net

this is a user control code is below
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UC_virtual_keyboard
{
    public partial class UserControl1 : UserControl
    {
   
        public UserControl1()
        {
            InitializeComponent();
        }
        #region
        public delegate void sender1(string u);
        public event sender1 Click1;
        public static string s = string.Empty;
        #endregion
        private void btnOne_Click(object sender, EventArgs e)
        {
           
            Button btn = (Button)sender;
            switch (btn.Name)
            {
                case "btnOne":
                    s = s + "1";
                    break;
                case "btnTwo":
                    s = s + "2";
                    break;
                case "btnThree":
                    s = s + "3";
                    break;
                case "btnFour":
                    s = s + "4";
                    break;
                case "btnFive":
                    s = s + "5";
                    break;
                case "btnSix":
                    s = s + "6";
                    break;
                case "btnSeven":
                    s = s + "7";
                    break;
                case "btnEight":
                    s = s + "8";
                    break;
                case "btnNine":
                    s = s + "9";
                    break;
                case "btnZero":
                    s = s + "0";
                    break;
                case "btnsub":
                    s = s + "_";
                    break;
                case "btnequal":
                    s = s + "=";
                    break;
                case "btnback":
                    if (s.Length > 0)
                        s = s.Substring(0, (s.Length - 1));
                    break;
                case "btnq":
                    s = s + "q";
                    break;
                case "btnw":
                    s = s + "w";
                    break;
                case "btne":
                    s = s + "e";
                    break;
                case "btnr":
                    s = s + "r";
                    break;
                case "btnt":
                    s = s + "t";
                    break;
                case "btny":
                    s = s + "y";
                    break;
                case "btnu":
                    s = s + "u";
                    break;
                case "btni":
                    s = s + "i";
                    break;
                case "btno":
                    s = s + "o";
                    break;
                case "btnp":
                    s = s + "p";
                    break;
                case "btnsqt":
                    s = s + "[";
                    break;
                case "btnsqru":
                    s = s + "]";
                    break;
                case "btndel":
                    s =" ";
                    break;
                case "btnenter":
                    s = s + System.Environment.NewLine;
                    break;
                case "btna":
                    s = s + "a";
                    break;
                case "btns":
                    s = s + "s";
                    break;
                case "btnd":
                    s = s + "d";
                    break;
                case "btnf":
                    s = s + "f";
                    break;
                case "btng":
                    s = s + "g";
                    break;
                case "btnh":
                    s = s + "h";
                    break;
                case "btnj":
                    s = s + "j";
                    break;
                case "btnk":
                    s = s + "k";
                    break;
                case "btnl":
                    s = s + "l";
                    break;
                case "btnsemi":
                    s = s + ";";
                    break;
                case "btncom":
                    s = s + "'";
                    break;
                case "btnbackslace":
                    s = s + "\\";
                    break;
                case "btnz":
                    s = s + "z";
                    break;
                case "btnx":
                    s = s + "x";
                    break;
                case "btnc":
                    s = s + "c";
                    break;
                case "btnv":
                    s = s + "v";
                    break;
                case "btnb":
                    s = s + "b";
                    break;
                case "btnn":
                    s = s + "n";
                    break;
                case "btnm":
                    s = s + "m";
                    break;
                case "btncomma":
                    s = s + ",";
                    break;
                case "btndot":
                    s = s + ".";
                    break;
                case "btnslace":
                    s = s + "/";
                    break;
                case "btnspace":
                    s = s + " ";
                    break;
                case "btnco":
                    s = s + "`";
                    break;
                case "btntab":
                    s = s + "+";
                    break;
                case "btnesc":
                    s = s + "*";
                    break;
                case "btnhome":
                    s = s + "%";
                    break;
                case "btnend":
                    s = s + "-";
                    break;
                default:
                    s = "";
                    break;

            }
            if (Click1 != null)
                Click1(s);

        }

       }

}


emplement page code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using UC_virtual_keyboard;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace testkeyboard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        #region
        int i = 1;
        #endregion
        private void Form1_Load(object sender, EventArgs e)
        {
            userControl11.Click1 += new UserControl1.sender1(userControl11_Click1);
        }
        private void userControl11_Click1(string s)
        {
            if (i == 1)
                textBox1.Text = s;
            else if (i == 2)
                textBox2.Text = s;
            else if (i == 3)
                textBox3.Text = s;
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            i=1;
            if (textBox1.Text == "")
                UserControl1.s = "";
            else
                UserControl1.s = textBox1.Text;
              
        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            i = 2;
            if (textBox2.Text == "")
                UserControl1.s = "";
            else
                UserControl1.s = textBox2.Text;

        }

        private void textBox3_Enter(object sender, EventArgs e)
        {
            i = 3;
            if (textBox3.Text == "")
                UserControl1.s = "";
            else
                UserControl1.s = textBox3.Text;


        }

        private void button2_Click(object sender, EventArgs e)
        {
            i = 1;
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox1.Focus();
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("One record saved.");
            button2_Click(sender, e);  
        }

    }
}

No comments:

Post a Comment