本文介绍了WebForm触摸屏应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个触摸屏应用程序,该应用程序基本上显示一个数字键盘,并允许其用于键入在文本框中显示的值.我已经设计并连接了大部分表单,但是我无法使数据正确显示在文本框中.实际上,在删除数据之前,程序会炸弹,因为我删除了一些处理EditValueChanged的代码,而且我不确定如何对其进行重新编码.
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.
推荐答案
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;
}
}
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)
//{
//}
}
}
这篇关于WebForm触摸屏应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!