| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- 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 ucNumberKey2 : UserControl
- {
- public ucNumberKey2()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 默认控制进行数字验证
- /// </summary>
- public bool bControl = true;
- public string strValue = "";
- /// <summary>
- /// 主界面调用填充数值
- /// </summary>
- public event EventSetNumKey evoice;
- private void btnValue_Click(object sender, EventArgs e)
- {
- Button btn = (Button)sender;
- int m = 0;
- if (txtValue1.Text.Length < 3)
- {
- iFocus = 1;
- setTxtValue1(btn, m);
- }
- else if (txtValue2.Text.Length < 3)
- {
- iFocus = 2;
- setTxtValue2(btn, m);
- }
- else if (txtValue3.Text.Length < 3)
- {
- iFocus = 3;
- setTxtValue3(btn, m);
- }
- }
- private void setTxtValue1(Button btn, int m)
- {
- int i = txtValue1.SelectionStart;
- txtValue1.Focus();
- txtValue1.Text = txtValue1.Text.Trim() + btn.Text;
- txtValue1.Select(++i + m, 0);
- }
- private void setTxtValue2(Button btn, int m)
- {
- int i = txtValue2.SelectionStart;
- txtValue2.Focus();
- txtValue2.Text = txtValue2.Text.Trim() + btn.Text;
- txtValue2.Select(++i + m, 0);
- }
- private void setTxtValue3(Button btn, int m)
- {
- int i = txtValue1.SelectionStart;
- txtValue3.Focus();
- txtValue3.Text = txtValue3.Text.Trim() + btn.Text;
- txtValue3.Select(++i + m, 0);
- }
- private void btnClean_Click(object sender, EventArgs e)
- {
- txtValue1.Text = "";
- txtValue2.Text = "";
- txtValue3.Text = "";
- }
- int iFocus = 1;
- private void btnLeft_Click(object sender, EventArgs e)
- {
- switch (iFocus)
- {
- case 1:
- txtValue1.Focus();
- break;
- case 2:
- txtValue2.Focus();
- break;
- case 3:
- txtValue3.Focus();
- break;
- }
- if (txtValue3.Focused && txtValue3.Text != "")
- {
- int i = txtValue3.SelectionStart;
- if (i > 0)
- {
- iFocus = 3;
- txtValue3.Focus();
- txtValue3.Select(--i, 0);
- }
- else
- {
- iFocus = 2;
- txtValue2.Focus();
- txtValue2.Select(3, 0);
- }
- }
- else if (txtValue2.Focused && txtValue2.Text != "")
- {
- int i = txtValue2.SelectionStart;
- if (i > 0)
- {
- iFocus = 2;
- txtValue2.Focus();
- txtValue2.Select(--i, 0);
- }
- else
- {
- iFocus = 1;
- txtValue1.Focus();
- txtValue1.Select(3, 0);
- }
- }
- else if (txtValue1.Focused && txtValue1.Text != "")
- {
- iFocus = 1;
- int i = txtValue1.SelectionStart;
- txtValue1.Focus();
- if (i > 0)
- txtValue1.Select(--i, 0);
- }
- }
- private void btnRight_Click(object sender, EventArgs e)
- {
- switch (iFocus)
- {
- case 1:
- txtValue1.Focus();
- break;
- case 2:
- txtValue2.Focus();
- break;
- case 3:
- txtValue3.Focus();
- break;
- }
- if (txtValue1.Focused && txtValue1.Text != "")
- {
- int i = txtValue1.SelectionStart;
- txtValue1.Focus();
- if (i < txtValue1.Text.Trim().Length)
- {
- txtValue1.Select(++i, 0);
- }
- else
- {
- iFocus = 2;
- txtValue2.Focus();
- }
- }
- else if (txtValue2.Focused && txtValue2.Text != "")
- {
- int i = txtValue2.SelectionStart;
- txtValue2.Focus();
- if (i < txtValue2.Text.Trim().Length)
- {
- txtValue2.Select(++i, 0);
- }
- else
- {
- iFocus = 3;
- txtValue3.Focus();
- }
- }
- else if (txtValue3.Focused && txtValue3.Text != "")
- {
- int i = txtValue3.SelectionStart;
- iFocus = 3;
- txtValue3.Focus();
- if (i < txtValue3.Text.Trim().Length)
- {
- txtValue3.Select(++i, 0);
- }
- }
- }
- private void btnBack_Click(object sender, EventArgs e)
- {
- if (txtValue3.Text != "")
- {
- iFocus = 3;
- int i = txtValue3.SelectionStart;
- txtValue3.Focus();
- if (i > 0)
- {
- txtValue3.Text = txtValue3.Text.Trim().Substring(0, i - 1) + txtValue3.Text.Trim().Substring(i);
- txtValue3.Select(--i, 0);
- }
- }
- else if (txtValue2.Text != "")
- {
- iFocus = 2;
- int i = txtValue2.SelectionStart;
- txtValue2.Focus();
- if (i > 0)
- {
- txtValue2.Text = txtValue2.Text.Trim().Substring(0, i - 1) + txtValue2.Text.Trim().Substring(i);
- txtValue2.Select(--i, 0);
- }
- }
- else if (txtValue1.Text != "")
- {
- iFocus = 1;
- int i = txtValue1.SelectionStart;
- txtValue1.Focus();
- if (i > 0)
- {
- txtValue1.Text = txtValue1.Text.Trim().Substring(0, i - 1) + txtValue1.Text.Trim().Substring(i);
- txtValue1.Select(--i, 0);
- }
- }
- }
- private void btnSubmit_Click(object sender, EventArgs e)
- {
- strValue = txtValue1.Text.Trim() + txtValue2.Text.Trim() + txtValue3.Text.Trim();
- txtValue1.Text = "";
- txtValue2.Text = "";
- txtValue3.Text = "";
- evoice(this, strValue);
- //此处还需调用加载该用户控件的界面关闭方法
- }
- }
- }
|