Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to write a touch screen app that basically displays a numeric key-pad and allows the used to key in a value that is displayed in a textbox. I have the form designed and wired up for the most part but I am having trouble getting the data to display correctly in the textbox. Actually the program bombs before the data is diplayed because I deleted some code dealing with EditValueChanged and I'm not sure how to recode it.
Posted
Comments
Dirk C De Winnaar 29-Sep-11 11:07am    
Post you code please Tim.

Tim,

Unless it's some funky touchscreen, it should be handled like a mouse. That means you don't need to do any special programming to make it work, just handle the buttons on the keypad with the mouse event handlers (I use mouseup, because then if a person hits the wrong button it lets him move off it before he lets up, so it cuts bad clicks).

Without the code, we can't see what's wrong, but basically what you want to do is when a mouse event is fired for the keypad, you'll add the character represented by the button to the textbox's text. So, if the user hit's button "4" then you would add a 4 to the text.

When a clear or backspace button is clicked, you would just change the textbox text appropriately.

Good luck, and pls post the code if you need more help.

Incidentally, if you're like us and need to run on a shoestring budget, we go with Magic-Touch touchscreen addons. They're cheaper then new ones, and sit on top of the monitor. You do get some paralax, although calibration is easy and helps. I don't have it at my fingertips, but if you need our 3rd party supplier, let me know and I'll send you the contact information I have. It might take a day or so to find, though.

As to the decimal point, I would use a property for the data, then have the property transform the data & update the textbox when it's set. It's in vb.net first, then converted to c# for you.

vb.net

VB
Private vData As String = ""
   Public Property Data As String
       Get
           Return vData
       End Get
       Set(ByVal value As String)
           vData = value
           Dim temp As String = Data
           Do While temp.Length < 3
               temp = "0" + temp
           Loop
           temp = temp.Substring(0, temp.Length - 2) + "." + temp.Substring(temp.Length - 2, 2)
           textedit1.text = temp
       End Set
   End Property


c#

C#
private string vData = "";
public string Data {
    get { return vData; }
    set {
        vData = value;
        string temp = Data;
        while (temp.Length < 3) {
            temp = "0" + temp;
        }
        temp = temp.Substring(0, temp.Length - 2) + "." + temp.Substring(temp.Length - 2, 2);
        textedit1.text = temp;
    }
}
 
Share this answer
 
v3
Comments
TimGMitch 29-Sep-11 12:15pm    
Excellent, thanks Bert!
Below is the code. I have the button click functionlaity working now. Is there a way to format my textbox, textEdit2, so that the user will not have to input the the decimnal? eg: if they wanted to enter "1.25" they would just enter "125".





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data.Linq;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void KeyPad_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            switch (button.Text)
            {
                case "Clear":
                    textEdit2.Text = String.Empty;
                    break;
                case "Reset":
                    textEdit1.Text = String.Empty;
                    clearLabels();
                    textEdit1.Focus();
                    break;
                default:
                    textEdit2.Text += button.Text;
                    break;
            }
        }
        private void LoadEmployeeData()
        {
            if (textEdit1.Text.Length == 9)
            {
                try
                {
                    using (TouchScreenChargeDataContext dc = new TouchScreenChargeDataContext())
                    {
                        Table<EMPLOYEES_SAMC> eTable = dc.GetTable<EMPLOYEES_SAMC>();
                        EMPLOYEES_SAMC e = (from emp in eTable where emp.BadgeNumber == textEdit1.Text select emp).SingleOrDefault();
                        if (e != null)
                        {
                            label1.Text = e.FullName;
                            label2.Text = e.EmployeeNumber;
                            label3.Text = e.Department;
                            label4.Text = e.JobTitle;
                            textEdit2.Focus();
                        }
                        else
                        {
                            clearLabels();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Cannot connect to Database. Please try again later");
                }
            }
        } 
        private void clearLabels()
        {
            label1.Text = string.Empty;
            label2.Text = string.Empty;
            label3.Text = string.Empty;
            label4.Text = string.Empty;
        }
        private void textEdit1_KeyUp(object sender, KeyEventArgs e)
        {
            if (textEdit1.Text.Length > 9)
            {
                textEdit1.Text = string.Empty;
            }
            if (textEdit1.Text.Length == 9)
            {
                Reset.Focus();
                LoadEmployeeData();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
           Decimal amt;
           if (Decimal.TryParse(textEdit2.Text, out amt) && amt > 0 && amt < 9999)
           {
               using (TouchScreenChargeDataContext dc = new TouchScreenChargeDataContext())
               {
                   Table<EMPLOYEES_SAMC> eTable = dc.GetTable<EMPLOYEES_SAMC>();
                   EMPLOYEES_SAMC employee = (from emp in eTable where emp.BadgeNumber == textEdit1.Text select emp).SingleOrDefault();
                   if (employee != null)
                   {
                       Charge newCharge = new Charge();
                       newCharge.EmployeeNumber = employee.EmployeeNumber;
                       newCharge.BadgeNumber = employee.BadgeNumber;
                       newCharge.EmployeeName = employee.FullName;
                       newCharge.Amount = Decimal.Parse(textEdit2.Text);
                       newCharge.TimeStamp = DateTime.Now;
                       newCharge.Location = System.Environment.MachineName.ToUpper().Trim();
                       dc.Charges.InsertOnSubmit(newCharge);
                       dc.SubmitChanges();
                       MessageBox.Show("Transaction Complete");
                   }
                   textEdit1.Text = String.Empty;
                   textEdit1.Focus();
                   clearLabels();
                   textEdit2.Text = String.Empty;
               }
           }
           else
           {
               MessageBox.Show("Invalid Amount");
               KeyPad_Click(button13, new EventArgs());
           }
        }
        //private void textEdit2_EditValueChanged(object sender, EventArgs e)
        //{
            
        //}
    }
  }
 
Share this answer
 

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