键盘pos机,WinFrom自定义控件系列

 新闻资讯  |   2023-05-10 09:42  |  投稿人:pos机之家

网上有很多关于键盘pos机,WinFrom自定义控件系列的知识,也有很多人为大家解答关于键盘pos机的问题,今天pos机之家(www.poszjia.com)为大家整理了关于这方面的知识,让我们一起来看下吧!

本文目录一览:

1、键盘pos机

键盘pos机

前提

入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

本系列文章将讲解各种控件的开发及思路,欢迎各位批评指正。

此系列控件开发教程将全部在原生控件基础上进行重绘开发,目标的扁平化、漂亮、支持触屏。

如果有什么好的建议也可以评论留言来交流。

源码地址:

GitHub:https://github.com/kwwwvagaa/NetWinformControl

码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果觉得写的还行,请点个 star 支持一下吧

欢迎前来交流探讨: 企鹅群568015492

目录

http://toutiao.com/item/6824291838963220999/

准备工作

键盘控件目前分为4中,英文键盘,数字键盘,支付键盘,手写键盘

键盘一般用在到文本框弹出的键盘,那么为什么到现在还没有看到文本框的影子呢?因为文本框的某些功能牵扯到了自定义窗体,所以准备在自定义窗体介绍之后再来说文本框。

本篇文章介绍数字键盘和支付键盘,手写键盘将在后面文本框控件介绍是提及到,此处不单独介绍

开始

首先来说数字键盘

添加用户控件,命名UCKeyBorderNum

全部功能代码如下,没有太多东西

1 private bool useCustomEvent = false; 2 /// <summary> 3 /// 是否使用自定义的事件来接收按键,当为true时将不再向系统发送按键请求 4 /// </summary> 5 [Description("是否使用自定义的事件来接收按键,当为true时将不再向系统发送按键请求"), Category("自定义")] 6 public bool UseCustomEvent 7 { 8 get { return useCustomEvent; } 9 set { useCustomEvent = value; }10 }11 [Description("数字点击事件"), Category("自定义")]12 public event EventHandler NumClick;13 [Description("删除点击事件"), Category("自定义")]14 public event EventHandler BackspaceClick;15 [Description("回车点击事件"), 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 }

计效果

下面说支付键盘,这个可能就比较小众的键盘了,支持根据输入金额自动计算可能付款金额

添加用户控件,命名UCKeyBorderPay

同样的东西不多,主要的就一个计算预估付款金额

1 [Description("数字点击事件"), Category("自定义")] 2 public event EventHandler NumClick; 3 4 [Description("取消点击事件"), Category("自定义")] 5 public event EventHandler CancelClick; 6 7 [Description("确定点击事件"), Category("自定义")] 8 public event EventHandler OKClick; 9 10 [Description("删除点击事件"), Category("自定义")] 11 public event EventHandler BackspaceClick; 12 13 [Description("金额点击事件"), Category("自定义")] 14 public event EventHandler MoneyClick; 15 public UCKeyBorderPay() 16 { 17 InitializeComponent(); 18 } 19 20 #region 设置快速付款金额 21 /// <summary> 22 /// 功能描述:设置快速付款金额 23 /// 作者:HZH 24 /// 创建日期:2019-03-07 11:41:04 25 /// 任务编号: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" />

计效果

那4个空白的位置就是用来填充预估付款金额的

用处及效果

使用方法将在后面的文本框处详细介绍

最后的话如果你喜欢的话,请到 码云或Github 点个星星吧

以上就是关于键盘pos机,WinFrom自定义控件系列的知识,后面我们会继续为大家整理关于键盘pos机的知识,希望能够帮助到大家!

转发请带上网址:http://www.poszjia.com/news/39497.html

你可能会喜欢:

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 babsan@163.com 举报,一经查实,本站将立刻删除。