Click here to Skip to main content
Click here to Skip to main content

Tagged as

C# UserControl TouchScreen Keypad Eng/Korean

, 16 Jun 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
UserControl for Eng/Korean and numeric touch-screen keypad

English

Korean

Numeric

Introduction

This tip is intended to demonstrate how to create a touchscreen UserControl Keypad interface for WinForms. This User Control is easy to use in WinForms. When we are working on a project like touchscreen WinForms applications, keypad design and development takes a major part. In many forms, we need to use the keypads. To minimize the code, we can create a keypad as usercontrol and can use it in multiple forms. The main purpose of creating this user control is for the multi-language use. Here I have created the user control with Korean and English language and the design of the Usercontrol is like a keypad of mobile applications. User can also add any language easily to this user control and use for their projects.

Background

In Touchscreen application development, keypad development is a major part. Keypad needs to be used in all forms. To avoid duplicate code, I planned to make the keypad as a Usercontrol. And also, this user control has feature as multi-language. This is a simple and easy to use multi Language usercontrol Keypad for Touch Screen applications.

Using the Code

How to Create User Control

First, create a Class library project and remove the class file and add a usercontrol instead of that. Design your touch screen layout and add all buttons needed for the touch screen. And add First Create a user Control. Buttons from A to Z set the same Click Event name ex for buttons A to Z. More detailed code explanation is as follows.

Declare the Variables

//
#region Attributes
////////////////////////////////
public bool capsOn = false;
public bool hangulOn = false;
public bool numbersOn = false;
public string keypaReturnVal = "";

#endregion

User Control Load event declares all the Button Events and in Button event, write appropriate functions:

//
#region Button & ETC Click Events (???? ?????)
/////////////// Common Functions ////////////////////
void ShanubtnClearClicks(object sender, EventArgs e)
{
    keypaReturnVal = "";
}
/// <summary>
/// All Button Click Events
/// </summary>
/// 

void ShanubtnClicks(object sender, EventArgs e)
{
    DevExpress.XtraEditors.SimpleButton button = 
        sender as DevExpress.XtraEditors.SimpleButton;
    string buttonText = button.Text;

    keypaReturnVal = keypaReturnVal + buttonText;
    if (!this.Focused)
        this.Focus();
}

/// <summary>
/// Space Button Click Events
/// </summary>
/// 

void ShanubtnSpaceClicks(object sender, EventArgs e)
{
    //DevExpress.XtraEditors.SimpleButton button = 
    //   sender as DevExpress.XtraEditors.SimpleButton;
    //string buttonText = button.Text;
    keypaReturnVal = keypaReturnVal + " ";
    //textBox1.Text = keypaReturnVal;
}

/// <summary>
/// BackSpace Button Click Events
/// </summary>
/// 

void ShanubtnBackSpaceClicks(object sender, EventArgs e)
{
    if (keypaReturnVal.Length > 0)
    {
        keypaReturnVal = keypaReturnVal.Remove(keypaReturnVal.Length - 1, 1);
    }
}

/// <summary>
/// Button Caps Lock Loading
/// </summary>
/// 

void ShanubtnCapsClicks(object sender, EventArgs e)
{
    if (hangulOn == true)
    {
        return;
    }
    if (numbersOn == true)
    {
        return;
    }
    if (capsOn == false)
    {
        capsOn = true;
        btnCaps.Text = btnCaps.Text.ToUpper();
        this.btnCaps.Image = global::SHANUPADUC.Properties.Resources.uparrow;
    }
    else
    {
        capsOn = false;
        btnCaps.Text = btnCaps.Text.ToLower();
        this.btnCaps.Image = global::SHANUPADUC.Properties.Resources.arrowdown;
    }
    loadCaps();
}

void ShanubtnLangClicks(object sender, EventArgs e)
{
    numbersOn = false;
    if (hangulOn == false)
    {
        hangulOn = true;
        this.btnLang.Image = global::SHANUPADUC.Properties.Resources.KOR_32;
    }
    else
    {
        hangulOn = false;
        this.btnLang.Image = global::SHANUPADUC.Properties.Resources.ENG_32;
    }
    loadbtnLang();
}

void ShanubtnNumberClicks(object sender, EventArgs e)
{
    if (numbersOn == false)
    {
        numbersOn = true;
    }
    else
    {
        numbersOn = false;
    }
    loadbtnNumbers();
}
#endregion  

Compile and run the project.

Adding the DLL to Winform and Using in your Project

Add the DLL in your Winform. Place the usercontrol where needed in your forms. In WinForms, we need to handle the UC click events and need to set the focused textbox for the keypad button text display in the Textbox. Use this code in form Initialization for UC settings.

//
public Form1()
{
    InitializeComponent();
    WireAllControls(shanukeypaduc1);
}

private void WireAllControls(Control cont)
{
    foreach (Control ctl in cont.Controls)
    {
        ctl.Click += ctl_Click;
        if (ctl.HasChildren)
        {
            WireAllControls(ctl);
        }
       // ctl.DoubleClick += jnkckeypaduc1_DoubleClick;
    }

    //to get the Textbox Focused

    foreach (TextBox tb in this.Controls.OfType<TextBox>())
    {
        tb.Enter += textBox_Enter;
    }

   // jnkcKeyPadcs1.DoubleClick+=new EventHandler(jnkcKeyPadcs1_DoubleClick);
}

//void jnkckeypaduc1_DoubleClick(object sender, EventArgs e)
//{
//  //  jnkckeypaduc1.Visible = false;
//}

void textBox_Enter(object sender, EventArgs e)
{
    focusedTextbox = (TextBox)sender;
    shanukeypaduc1.keypaReturnVal = focusedTextbox.Text;
}

private void ctl_Click(object sender, EventArgs e)
{
    this.InvokeOnClick(this, EventArgs.Empty);

    if (focusedTextbox != null)
    {
        // put something in textbox
        focusedTextbox.Text = shanukeypaduc1.keypaReturnVal;
    }

    //textBox1.Text = jnkcKeyPadcs1.keypaReturnVal;
}

Points of Interest

This User Control is simple to use in WinForms. Download it and use it in WinForms touch-screen projects.

History

  • 13th June, 2013 - First version
  • 17th June, 2013 - Ver1.1 - Updated Devexpress buttons to normal winform buttons,which can be used by all.

License

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

Share

About the Author

syed shanu
Team Leader
India India
Visit My SHANU C# Blog
Mr.Shanu is a Senior Software Engineer. He’s basically from India and working at South Korea for more than 7 years.


He has 9+ years of Experience in Microsoft Technologies. More than 7 Years of experience in Automation Fields, He has worked in several projects of MES, Automation, ERP and HMI programs like PLC, Sensor, RFID and Nutrunner Tools. He has worked in both Windows based and Web Based projects.


Shanu Love to learn and work with new technology.


His main hobbies are to spend time with Family and to create Different and Innvotive programs and write Article about his program and Share with others.

His Latest Article which he likes most was Windows Form Design at Run Time

His facebook page
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
QuestionThis was a tip PinprotectorOriginalGriff14-Jun-13 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 17 Jun 2013
Article Copyright 2013 by syed shanu
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid