📄 pinusercontrol.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;
namespace Chapter15.Windows.Forms
{
public partial class PinUserControl : UserControl
{
public PinUserControl()
{
#if !Smartphone
InitializeComponent();
#endif
}
public override string Text
{
get
{
#if !Smartphone
return txtPin.Text;
#else
return string.Empty;
#endif
}
}
public bool IsEntered
{
get
{
#if !Smartphone
return (txtPin.Text.Length == 4);
#else
return false;
#endif
}
}
private Color buttonColor = SystemColors.ActiveCaption;
public Color ButtonColor
{
get
{
return buttonColor;
}
set
{
buttonColor = value;
#if !Smartphone
btn0.BackColor = buttonColor;
btn1.BackColor = buttonColor;
btn2.BackColor = buttonColor;
btn3.BackColor = buttonColor;
btn4.BackColor = buttonColor;
btn5.BackColor = buttonColor;
btn6.BackColor = buttonColor;
btn7.BackColor = buttonColor;
btn8.BackColor = buttonColor;
btn9.BackColor = buttonColor;
btnBack.BackColor = buttonColor;
#endif
}
}
public event EventHandler PinChanged;
protected virtual void OnPinChanged(object sender, EventArgs e)
{
if (this.PinChanged != null)
{
PinChanged(sender, e);
}
}
private void btn_Click(object sender, EventArgs e)
{
#if !Smartphone
Button b = (Button)sender;
if (!IsEntered)
{
txtPin.Text += b.Text;
}
#endif
}
private void txtPin_TextChanged(object sender, EventArgs e)
{
OnPinChanged(sender, EventArgs.Empty);
}
private void btnBack_Click(object sender, EventArgs e)
{
#if !Smartphone
if (txtPin.Text.Length > 0)
{
txtPin.Text = txtPin.Text.Substring(0, txtPin.Text.Length - 1);
}
#endif
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -