using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace MeterModuleLibrary { public partial class ucLetterNumberKey : UserControl { public ucLetterNumberKey() { InitializeComponent(); } public string strValue = ""; private void btnSetValue_Click(object sender, EventArgs e) { Button btn = (Button)sender; int i = txtValue.SelectionStart; if (btn.Name == "btn00") { i++; } txtValue.Focus(); txtValue.Text = txtValue.Text.Trim() + btn.Text; txtValue.Select(++i, 0); } private void btnClean_Click(object sender, EventArgs e) { txtValue.Text = ""; } private void btnSubmit_Click(object sender, EventArgs e) { strValue = txtValue.Text.Trim(); txtValue.Text = ""; //此处还需调用加载该用户控件的界面关闭方法 } private void btnBack_Click(object sender, EventArgs e) { int i = txtValue.SelectionStart; txtValue.Focus(); if (i > 0) { txtValue.Text = txtValue.Text.Trim().Substring(0, i - 1) + txtValue.Text.Trim().Substring(i); txtValue.Select(--i, 0); } } private void btnLeft_Click(object sender, EventArgs e) { int i = txtValue.SelectionStart; txtValue.Focus(); if (i>0) txtValue.Select(--i, 0); } private void btnRight_Click(object sender, EventArgs e) { int i = txtValue.SelectionStart; txtValue.Focus(); if (i < txtValue.Text.Trim().Length) txtValue.Select(++i, 0); } } }