基本信息
源码名称:C# 数字键盘(用户自定义控件示例源码)
源码大小:0.32M
文件格式:.zip
开发语言:C#
更新时间:2018-02-22
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
可以始终保持在最顶端的数字键盘
可以始终保持在最顶端的数字键盘
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Paway.Windows.Forms
{
public partial class NumKeyBord : UserControl
{
//定义委托
public delegate void NumKeyBordClickHandle(object sender, EventArgs e);
//定义事件
public event NumKeyBordClickHandle NumKeyBordClick;
#region Property
private Color _keyBordBackColor = Color.LightCyan;
[Browsable(true)]
[Description("控件背景颜色")]
public Color KeyBordBackColor
{
get { return _keyBordBackColor; }
set
{
_keyBordBackColor = value;
this.tableLayoutPanel1.BackColor = _keyBordBackColor;
base.Invalidate();
}
}
private Color _keyForeColor = Color.Black;
[Browsable(true)]
[Description("数字字体颜色")]
public Color KeyForeColor
{
get { return _keyForeColor; }
set
{
_keyForeColor = value;
foreach (Control ctl in tableLayoutPanel1.Controls)
{
if (ctl is Button)
{
(ctl as Button).ForeColor = _keyForeColor;
}
}
base.Invalidate();
}
}
private Control _targetControl;
[Browsable(true)]
[Description("接收数字的控件")]
public Control TargetControl
{
get { return _targetControl; }
set
{
_targetControl = value;
base.Invalidate();
}
}
#endregion
#region Constructer
public NumKeyBord()
{
InitializeComponent();
InitKeyboard();
}
#endregion
private void InitKeyboard()
{
foreach (Control ctl in tableLayoutPanel1.Controls)
{
if (ctl is Button)
{
(ctl as Button).ForeColor = Color.Black;
(ctl as Button).Click = btnNum_Click;
}
}
}
private void btnNum_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
if (btn == null) return;
string str = btn.Text;
if (str == "关闭")
{
NumKeyBordClick?.Invoke(btn, e);
this.Hide();
//this.Dispose();
return;
}
else if (str == "<")
{
if (this._targetControl.Text.Length > 0)
_targetControl.Text = _targetControl.Text.Substring(0, _targetControl.Text.Length - 1);
}
else
{
this.TargetControl.Text = str;
}
}
private void TopLevelControl_MouseClick(object sender, MouseEventArgs e)
{
if (!this.Bounds.Contains(e.X, e.Y))
{
this.Hide();
//this.Dispose();
}
}
}
}