網(wǎng)上有很多關(guān)于鍵盤式pos機(jī),WinFrom自定義控件系列的知識(shí),也有很多人為大家解答關(guān)于鍵盤式pos機(jī)的問題,今天pos機(jī)之家(m.afbey.com)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來看下吧!
本文目錄一覽:
鍵盤式pos機(jī)
前提入行已經(jīng)7,8年了,一直想做一套漂亮點(diǎn)的自定義控件,于是就有了本系列文章。
本系列文章將講解各種控件的開發(fā)及思路,歡迎各位批評(píng)指正。
此系列控件開發(fā)教程將全部在原生控件基礎(chǔ)上進(jìn)行重繪開發(fā),目標(biāo)的扁平化、漂亮、支持觸屏。
如果有什么好的建議也可以評(píng)論留言來交流。
源碼地址:
GitHub:https://github.com/kwwwvagaa/NetWinformControl
碼云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果覺得寫的還行,請(qǐng)點(diǎn)個(gè) star 支持一下吧
歡迎前來交流探討: 企鵝群568015492
目錄http://toutiao.com/item/6824291838963220999/
準(zhǔn)備工作鍵盤控件目前分為4中,英文鍵盤,數(shù)字鍵盤,支付鍵盤,手寫鍵盤
鍵盤一般用在到文本框彈出的鍵盤,那么為什么到現(xiàn)在還沒有看到文本框的影子呢?因?yàn)槲谋究虻哪承┕δ軤砍兜搅俗远x窗體,所以準(zhǔn)備在自定義窗體介紹之后再來說文本框。
本篇文章介紹數(shù)字鍵盤和支付鍵盤,手寫鍵盤將在后面文本框控件介紹是提及到,此處不單獨(dú)介紹
開始首先來說數(shù)字鍵盤
添加用戶控件,命名UCKeyBorderNum
全部功能代碼如下,沒有太多東西
1 private bool useCustomEvent = false; 2 /// <summary> 3 /// 是否使用自定義的事件來接收按鍵,當(dāng)為true時(shí)將不再向系統(tǒng)發(fā)送按鍵請(qǐng)求 4 /// </summary> 5 [Description("是否使用自定義的事件來接收按鍵,當(dāng)為true時(shí)將不再向系統(tǒng)發(fā)送按鍵請(qǐng)求"), Category("自定義")] 6 public bool UseCustomEvent 7 { 8 get { return useCustomEvent; } 9 set { useCustomEvent = value; }10 }11 [Description("數(shù)字點(diǎn)擊事件"), Category("自定義")]12 public event EventHandler NumClick;13 [Description("刪除點(diǎn)擊事件"), Category("自定義")]14 public event EventHandler BackspaceClick;15 [Description("回車點(diǎn)擊事件"), Category("自定義")]16 public event EventHandler EnterClick;17 public UCKeyBorderNum()18 {19 InitializeComponent();20 }21 22 private void Num_MouseDown(object sender, MouseEventArgs e)23 {24 if (NumClick != null)25 {26 NumClick(sender, e);27 }28 if (useCustomEvent)29 return;30 Label lbl = sender as Label;31 SendKeys.Send(lbl.Tag.ToString());32 }33 34 private void Backspace_MouseDown(object sender, MouseEventArgs e)35 {36 if (BackspaceClick != null)37 {38 BackspaceClick(sender, e);39 }40 if (useCustomEvent)41 return;42 Label lbl = sender as Label;43 SendKeys.Send("{BACKSPACE}");44 }45 46 private void Enter_MouseDown(object sender, MouseEventArgs e)47 {48 if (EnterClick != null)49 {50 EnterClick(sender, e);51 }52 if (useCustomEvent)53 return;54 SendKeys.Send("{ENTER}");55 }
計(jì)效果
下面說支付鍵盤,這個(gè)可能就比較小眾的鍵盤了,支持根據(jù)輸入金額自動(dòng)計(jì)算可能付款金額
添加用戶控件,命名UCKeyBorderPay
同樣的東西不多,主要的就一個(gè)計(jì)算預(yù)估付款金額
1 [Description("數(shù)字點(diǎn)擊事件"), Category("自定義")] 2 public event EventHandler NumClick; 3 4 [Description("取消點(diǎn)擊事件"), Category("自定義")] 5 public event EventHandler CancelClick; 6 7 [Description("確定點(diǎn)擊事件"), Category("自定義")] 8 public event EventHandler OKClick; 9 10 [Description("刪除點(diǎn)擊事件"), Category("自定義")] 11 public event EventHandler BackspaceClick; 12 13 [Description("金額點(diǎn)擊事件"), Category("自定義")] 14 public event EventHandler MoneyClick; 15 public UCKeyBorderPay() 16 { 17 InitializeComponent(); 18 } 19 20 #region 設(shè)置快速付款金額 21 /// <summary> 22 /// 功能描述:設(shè)置快速付款金額 23 /// 作者:HZH 24 /// 創(chuàng)建日期:2019-03-07 11:41:04 25 /// 任務(wù)編號(hào):POS 26 /// </summary> 27 /// <param name="SorceMoney">SorceMoney</param> 28 public void SetPayMoney(decimal SorceMoney) 29 { 30 List<decimal> list = new List<decimal>(); 31 decimal d = Math.Ceiling(SorceMoney); 32 if (SorceMoney > 0m) 33 { 34 if (SorceMoney < 5m) 35 { 36 list.Add(5m); 37 list.Add(10m); 38 list.Add(20m); 39 list.Add(50m); 40 } 41 else if (SorceMoney < 10m) 42 { 43 list.Add(10m); 44 list.Add(20m); 45 list.Add(50m); 46 list.Add(100m); 47 } 48 else 49 { 50 int num = Convert.ToInt32(d % 10m); 51 int num2 = Convert.ToInt32(Math.Floor(d / 10m) % 10m); 52 int num3 = Convert.ToInt32(Math.Floor(d / 100m)); 53 int num4; 54 if (num < 5) 55 { 56 num4 = num2 * 10 + 5; 57 list.Add(num4 + num3 * 100); 58 num4 = (num2 + 1) * 10; 59 list.Add(num4 + num3 * 100); 60 } 61 else 62 { 63 num4 = (num2 + 1) * 10; 64 list.Add(num4 + num3 * 100); 65 } 66 if (num4 >= 0 && num4 < 10) 67 { 68 num4 = 10; 69 if (list.Count < 4) 70 { 71 list.Add(num4 + num3 * 100); 72 } 73 num4 = 20; 74 if (list.Count < 4) 75 { 76 list.Add(num4 + num3 * 100); 77 } 78 num4 = 50; 79 if (list.Count < 4) 80 { 81 list.Add(num4 + num3 * 100); 82 } 83 num4 = 100; 84 if (list.Count < 4) 85 { 86 list.Add(num4 + num3 * 100); 87 } 88 } 89 else if (num4 >= 10 && num4 < 20) 90 { 91 num4 = 20; 92 if (list.Count < 4) 93 { 94 list.Add(num4 + num3 * 100); 95 } 96 num4 = 50; 97 if (list.Count < 4) 98 { 99 list.Add(num4 + num3 * 100);100 }101 num4 = 100;102 if (list.Count < 4)103 {104 list.Add(num4 + num3 * 100);105 }106 }107 else if (num4 >= 20 && num4 < 50)108 {109 num4 = 50;110 if (list.Count < 4)111 {112 list.Add(num4 + num3 * 100);113 }114 num4 = 100;115 if (list.Count < 4)116 {117 list.Add(num4 + num3 * 100);118 }119 }120 else if (num4 < 100)121 {122 num4 = 100;123 if (list.Count < 4)124 {125 list.Add(num4 + num3 * 100);126 }127 }128 }129 }130 SetFastMoneyToContrl(list);131 }132 #endregion133 134 private void SetFastMoneyToContrl(List<decimal> values)135 {136 List<Label> lbl = new List<Label>() { lblFast1, lblFast2, lblFast3, lblFast4 };137 lblFast1.Tag = lblFast1.Text = "";138 lblFast2.Tag = lblFast2.Text = "";139 lblFast3.Tag = lblFast3.Text = "";140 lblFast4.Tag = lblFast4.Text = "";141 for (int i = 0; i < lbl.Count && i < values.Count; i++)142 {143 if (values[i].ToString("0.##").Length < 4)144 {145 lbl[i].Font = new System.Drawing.Font("Arial Unicode MS", 30F);146 }147 else148 {149 Graphics graphics = lbl[i].CreateGraphics();150 for (int j = 0; j < 5; j++)151 {152 SizeF sizeF = graphics.MeasureString(values[i].ToString("0.##"), new System.Drawing.Font("Arial Unicode MS", 30 - j * 5), 100, StringFormat.GenericTypographic);153 if (sizeF.width="360px",height="auto" />
計(jì)效果
那4個(gè)空白的位置就是用來填充預(yù)估付款金額的
用處及效果使用方法將在后面的文本框處詳細(xì)介紹
最后的話如果你喜歡的話,請(qǐng)到 碼云或Github 點(diǎn)個(gè)星星吧以上就是關(guān)于鍵盤式pos機(jī),WinFrom自定義控件系列的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于鍵盤式pos機(jī)的知識(shí),希望能夠幫助到大家!
![](/style/images/zhouzong.jpg)