// ***********************************************************************
// Assembly : HZH_Controls
// Created : 08-08-2019
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
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 HZH_Controls.Controls
{
///
/// Class UCKeyBorderAll.
/// Implements the
///
///
[DefaultEvent("KeyDown")]
public partial class UCKeyBorderAll : UserControl
{
///
/// The character type
///
private KeyBorderCharType _charType = KeyBorderCharType.CHAR;
///
/// Gets or sets the type of the character.
///
/// The type of the character.
[Description("默认显示样式"), Category("自定义")]
public KeyBorderCharType CharType
{
get { return _charType; }
set
{
_charType = value;
if (value == KeyBorderCharType.CHAR)
{
if (label37.Text.ToLower() == "abc.")
{
CharOrNum();
}
}
else
{
if (label37.Text.ToLower() == "?123")
{
CharOrNum();
}
}
}
}
///
/// Occurs when [key click].
///
[Description("按键点击事件"), Category("自定义")]
public event EventHandler KeyClick;
///
/// Occurs when [enter click].
///
[Description("回车点击事件"), Category("自定义")]
public event EventHandler EnterClick;
///
/// Occurs when [backspace clike].
///
[Description("删除点击事件"), Category("自定义")]
public event EventHandler BackspaceClike;
///
/// Occurs when [retract clike].
///
[Description("收起点击事件"), Category("自定义")]
public event EventHandler RetractClike;
///
/// Initializes a new instance of the class.
///
public UCKeyBorderAll()
{
InitializeComponent();
}
///
/// Handles the MouseDown event of the KeyDown control.
///
/// The source of the event.
/// The instance containing the event data.
private void KeyDown_MouseDown(object sender, MouseEventArgs e)
{
Label lbl = sender as Label;
if (string.IsNullOrEmpty(lbl.Text))
{
return;
}
if (lbl.Text == "大写")
{
ToUper(true);
lbl.Text = "小写";
}
else if (lbl.Text == "小写")
{
ToUper(false);
lbl.Text = "大写";
}
else if (lbl.Text == "?123" || lbl.Text == "abc.")
{
CharOrNum();
}
else if (lbl.Text == "空格")
{
SendKeys.Send(" ");
}
else if (lbl.Text == "删除")
{
SendKeys.Send("{BACKSPACE}");
if (BackspaceClike != null)
BackspaceClike(sender, e);
}
else if (lbl.Text == "回车")
{
SendKeys.Send("{ENTER}");
if (EnterClick != null)
EnterClick(sender, e);
}
else if (lbl.Text == "收起")
{
if (RetractClike != null)
RetractClike(sender, e);
}
else
{
string Str = "{"+ lbl.Text + "}";
SendKeys.Send(lbl.Text);
}
if (KeyClick != null)
KeyClick(sender, e);
}
///
/// Converts to uper.
///
/// if set to true [BLN].
private void ToUper(bool bln)
{
foreach (Control item in this.tableLayoutPanel2.Controls)
{
if (item is Panel)
{
foreach (Control pc in item.Controls)
{
if (pc is Label)
{
if (pc.Text == "abc.")
break;
if (bln)
{
pc.Text = pc.Text.ToUpper();
}
else
{
pc.Text = pc.Text.ToLower();
}
break;
}
}
}
}
}
///
/// Characters the or number.
///
private void CharOrNum()
{
foreach (Control item in this.tableLayoutPanel2.Controls)
{
if (item is Panel)
{
foreach (Control pc in item.Controls)
{
if (pc is Label)
{
string strTag = pc.Text;
pc.Text = pc.Tag.ToString();
pc.Tag = strTag;
break;
}
}
}
}
}
}
///
/// Enum KeyBorderCharType
///
public enum KeyBorderCharType
{
///
/// The character
///
CHAR = 1,
///
/// The number
///
NUMBER = 2
}
}