using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
using UAS_SOP.Enum;
using UAS_SOP.Properties;
using UAS_SOP.PublicMethod;
namespace UAS_SOP.CustomControl.ButtonUtil
{
public partial class LockMakeCode : Button
{
#region 变量
///
/// 鼠标状态
///
private EMouseState _mouseState = EMouseState.Normal;
///
/// 文本对齐方式
///
private TextFormatFlags _textAlign = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
///
/// 默认时的按钮图片
///
private Image _normalImage = null;
///
/// 鼠标按下时的图片
///
private Image _downImage = null;
///
/// 鼠标划过时的图片
///
private Image _moveImage = null;
///
/// 是否按下了鼠标
///
private bool _isShowBorder = true;
///
/// 权限标识符
///
string Power1;
public string Power
{
get
{
return Power1;
}
set
{
Power1 = value;
}
}
string AllPower1;
public string AllPower
{
get
{
return AllPower1;
}
set
{
AllPower1 = value;
}
}
#endregion
#region 构造函数
public LockMakeCode()
{
InitializeComponent();
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.Selectable |
ControlStyles.DoubleBuffer |
ControlStyles.SupportsTransparentBackColor |
ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.Opaque, false);
base.BackColor = Color.Transparent;
this.UpdateStyles();
}
#endregion
#region 属性
///
/// 默认大小
///
protected override Size DefaultSize
{
get { return new Size(75, 28); }
}
///
/// 默认图片
///
///
/// 是否显示发光边框
///
[Description("是否显示发光边框")]
public virtual bool IsShowBorder
{
get { return this._isShowBorder; }
set { this._isShowBorder = value; }
}
///
/// 与控件相关的文本
///
[DefaultValue("QQButton")]
public override string Text
{
get { return base.Text; }
set
{
base.Text = value;
base.Invalidate(this.TextRect);
}
}
///
/// 按钮上显示的图片
///
[Description("按钮上显示的图片")]
public virtual new Image Image
{
get { return base.Image; }
set
{
base.Image = value;
base.Invalidate();
}
}
///
/// 按钮上文字的对齐方式
///
[Description("按钮上文字的对齐方式")]
new public ContentAlignment TextAlign
{
get { return base.TextAlign; }
set
{
base.TextAlign = value;
switch (base.TextAlign)
{
case ContentAlignment.BottomCenter:
this._textAlign = TextFormatFlags.Bottom |
TextFormatFlags.HorizontalCenter |
TextFormatFlags.SingleLine;
break;
case ContentAlignment.BottomLeft:
this._textAlign = TextFormatFlags.Bottom |
TextFormatFlags.Left |
TextFormatFlags.SingleLine;
break;
case ContentAlignment.BottomRight:
this._textAlign = TextFormatFlags.Bottom |
TextFormatFlags.Right |
TextFormatFlags.SingleLine;
break;
case ContentAlignment.MiddleCenter:
this._textAlign = TextFormatFlags.SingleLine |
TextFormatFlags.HorizontalCenter |
TextFormatFlags.VerticalCenter;
break;
case ContentAlignment.MiddleLeft:
this._textAlign = TextFormatFlags.Left |
TextFormatFlags.VerticalCenter |
TextFormatFlags.SingleLine;
break;
case ContentAlignment.MiddleRight:
this._textAlign = TextFormatFlags.Right |
TextFormatFlags.VerticalCenter |
TextFormatFlags.SingleLine;
break;
case ContentAlignment.TopCenter:
this._textAlign = TextFormatFlags.Top |
TextFormatFlags.HorizontalCenter |
TextFormatFlags.SingleLine;
break;
case ContentAlignment.TopLeft:
this._textAlign = TextFormatFlags.Top |
TextFormatFlags.Left |
TextFormatFlags.SingleLine;
break;
case ContentAlignment.TopRight:
this._textAlign = TextFormatFlags.Top |
TextFormatFlags.Right |
TextFormatFlags.SingleLine;
break;
}
base.Invalidate(this.TextRect);
}
}
///
/// 整个按钮的区域
///
internal Rectangle AllRect
{
get { return new Rectangle(0, 0, this.Width, this.Height); }
}
///
/// 文字区域
///
internal Rectangle TextRect
{
get { return new Rectangle(2, 2, this.AllRect.Width - 4, this.AllRect.Height - 4); }
}
///
/// 鼠标状态
///
internal EMouseState MouseState
{
get { return this._mouseState; }
set
{
this._mouseState = value;
base.Invalidate();
}
}
#endregion
///
/// 引发 System.Windows.Forms.Form.MouseEnter 事件。
///
/// 包含事件数据的 System.EventArgs。
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.MouseState = EMouseState.Move;
}
///
/// 引发 System.Windows.Forms.Form.MouseLeave 事件。
///
/// 包含事件数据的 System.EventArgs。
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.MouseState = EMouseState.Leave;
}
///
/// 引发 System.Windows.Forms.Form.MouseDown 事件。
///
/// 包含事件数据的 System.Windows.Forms.MouseEventArgs。
protected override void OnMouseDown(MouseEventArgs mevent)
{
base.OnMouseDown(mevent);
this.MouseState = EMouseState.Down;
}
///
/// 引发 System.Windows.Forms.Form.MouseUp 事件。
///
/// 包含事件数据的 System.Windows.Forms.MouseEventArgs。
protected override void OnMouseUp(MouseEventArgs mevent)
{
base.OnMouseUp(mevent);
this.MouseState = EMouseState.Up;
}
}
}