LockMakeCode.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Drawing.Text;
  6. using System.Windows.Forms;
  7. using UAS_SOP.Enum;
  8. using UAS_SOP.Properties;
  9. using UAS_SOP.PublicMethod;
  10. namespace UAS_SOP.CustomControl.ButtonUtil
  11. {
  12. public partial class LockMakeCode : Button
  13. {
  14. #region 变量
  15. /// <summary>
  16. /// 鼠标状态
  17. /// </summary>
  18. private EMouseState _mouseState = EMouseState.Normal;
  19. /// <summary>
  20. /// 文本对齐方式
  21. /// </summary>
  22. private TextFormatFlags _textAlign = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
  23. /// <summary>
  24. /// 默认时的按钮图片
  25. /// </summary>
  26. private Image _normalImage = null;
  27. /// <summary>
  28. /// 鼠标按下时的图片
  29. /// </summary>
  30. private Image _downImage = null;
  31. /// <summary>
  32. /// 鼠标划过时的图片
  33. /// </summary>
  34. private Image _moveImage = null;
  35. /// <summary>
  36. /// 是否按下了鼠标
  37. /// </summary>
  38. private bool _isShowBorder = true;
  39. /// <summary>
  40. /// 权限标识符
  41. /// </summary>
  42. string Power1;
  43. public string Power
  44. {
  45. get
  46. {
  47. return Power1;
  48. }
  49. set
  50. {
  51. Power1 = value;
  52. }
  53. }
  54. string AllPower1;
  55. public string AllPower
  56. {
  57. get
  58. {
  59. return AllPower1;
  60. }
  61. set
  62. {
  63. AllPower1 = value;
  64. }
  65. }
  66. #endregion
  67. #region 构造函数
  68. public LockMakeCode()
  69. {
  70. InitializeComponent();
  71. this.SetStyle(
  72. ControlStyles.AllPaintingInWmPaint |
  73. ControlStyles.OptimizedDoubleBuffer |
  74. ControlStyles.ResizeRedraw |
  75. ControlStyles.Selectable |
  76. ControlStyles.DoubleBuffer |
  77. ControlStyles.SupportsTransparentBackColor |
  78. ControlStyles.UserPaint, true);
  79. this.SetStyle(ControlStyles.Opaque, false);
  80. base.BackColor = Color.Transparent;
  81. this.UpdateStyles();
  82. }
  83. #endregion
  84. #region 属性
  85. /// <summary>
  86. /// 默认大小
  87. /// </summary>
  88. protected override Size DefaultSize
  89. {
  90. get { return new Size(75, 28); }
  91. }
  92. /// <summary>
  93. /// 默认图片
  94. /// </summary>
  95. /// <summary>
  96. /// 是否显示发光边框
  97. /// </summary>
  98. [Description("是否显示发光边框")]
  99. public virtual bool IsShowBorder
  100. {
  101. get { return this._isShowBorder; }
  102. set { this._isShowBorder = value; }
  103. }
  104. /// <summary>
  105. /// 与控件相关的文本
  106. /// </summary>
  107. [DefaultValue("QQButton")]
  108. public override string Text
  109. {
  110. get { return base.Text; }
  111. set
  112. {
  113. base.Text = value;
  114. base.Invalidate(this.TextRect);
  115. }
  116. }
  117. /// <summary>
  118. /// 按钮上显示的图片
  119. /// </summary>
  120. [Description("按钮上显示的图片")]
  121. public virtual new Image Image
  122. {
  123. get { return base.Image; }
  124. set
  125. {
  126. base.Image = value;
  127. base.Invalidate();
  128. }
  129. }
  130. /// <summary>
  131. /// 按钮上文字的对齐方式
  132. /// </summary>
  133. [Description("按钮上文字的对齐方式")]
  134. new public ContentAlignment TextAlign
  135. {
  136. get { return base.TextAlign; }
  137. set
  138. {
  139. base.TextAlign = value;
  140. switch (base.TextAlign)
  141. {
  142. case ContentAlignment.BottomCenter:
  143. this._textAlign = TextFormatFlags.Bottom |
  144. TextFormatFlags.HorizontalCenter |
  145. TextFormatFlags.SingleLine;
  146. break;
  147. case ContentAlignment.BottomLeft:
  148. this._textAlign = TextFormatFlags.Bottom |
  149. TextFormatFlags.Left |
  150. TextFormatFlags.SingleLine;
  151. break;
  152. case ContentAlignment.BottomRight:
  153. this._textAlign = TextFormatFlags.Bottom |
  154. TextFormatFlags.Right |
  155. TextFormatFlags.SingleLine;
  156. break;
  157. case ContentAlignment.MiddleCenter:
  158. this._textAlign = TextFormatFlags.SingleLine |
  159. TextFormatFlags.HorizontalCenter |
  160. TextFormatFlags.VerticalCenter;
  161. break;
  162. case ContentAlignment.MiddleLeft:
  163. this._textAlign = TextFormatFlags.Left |
  164. TextFormatFlags.VerticalCenter |
  165. TextFormatFlags.SingleLine;
  166. break;
  167. case ContentAlignment.MiddleRight:
  168. this._textAlign = TextFormatFlags.Right |
  169. TextFormatFlags.VerticalCenter |
  170. TextFormatFlags.SingleLine;
  171. break;
  172. case ContentAlignment.TopCenter:
  173. this._textAlign = TextFormatFlags.Top |
  174. TextFormatFlags.HorizontalCenter |
  175. TextFormatFlags.SingleLine;
  176. break;
  177. case ContentAlignment.TopLeft:
  178. this._textAlign = TextFormatFlags.Top |
  179. TextFormatFlags.Left |
  180. TextFormatFlags.SingleLine;
  181. break;
  182. case ContentAlignment.TopRight:
  183. this._textAlign = TextFormatFlags.Top |
  184. TextFormatFlags.Right |
  185. TextFormatFlags.SingleLine;
  186. break;
  187. }
  188. base.Invalidate(this.TextRect);
  189. }
  190. }
  191. /// <summary>
  192. /// 整个按钮的区域
  193. /// </summary>
  194. internal Rectangle AllRect
  195. {
  196. get { return new Rectangle(0, 0, this.Width, this.Height); }
  197. }
  198. /// <summary>
  199. /// 文字区域
  200. /// </summary>
  201. internal Rectangle TextRect
  202. {
  203. get { return new Rectangle(2, 2, this.AllRect.Width - 4, this.AllRect.Height - 4); }
  204. }
  205. /// <summary>
  206. /// 鼠标状态
  207. /// </summary>
  208. internal EMouseState MouseState
  209. {
  210. get { return this._mouseState; }
  211. set
  212. {
  213. this._mouseState = value;
  214. base.Invalidate();
  215. }
  216. }
  217. #endregion
  218. /// <summary>
  219. /// 引发 System.Windows.Forms.Form.MouseEnter 事件。
  220. /// </summary>
  221. /// <param name="e">包含事件数据的 System.EventArgs。</param>
  222. protected override void OnMouseEnter(EventArgs e)
  223. {
  224. base.OnMouseEnter(e);
  225. this.MouseState = EMouseState.Move;
  226. }
  227. /// <summary>
  228. /// 引发 System.Windows.Forms.Form.MouseLeave 事件。
  229. /// </summary>
  230. /// <param name="e">包含事件数据的 System.EventArgs。</param>
  231. protected override void OnMouseLeave(EventArgs e)
  232. {
  233. base.OnMouseLeave(e);
  234. this.MouseState = EMouseState.Leave;
  235. }
  236. /// <summary>
  237. /// 引发 System.Windows.Forms.Form.MouseDown 事件。
  238. /// </summary>
  239. /// <param name="mevent">包含事件数据的 System.Windows.Forms.MouseEventArgs。</param>
  240. protected override void OnMouseDown(MouseEventArgs mevent)
  241. {
  242. base.OnMouseDown(mevent);
  243. this.MouseState = EMouseState.Down;
  244. }
  245. /// <summary>
  246. /// 引发 System.Windows.Forms.Form.MouseUp 事件。
  247. /// </summary>
  248. /// <param name="mevent">包含事件数据的 System.Windows.Forms.MouseEventArgs。</param>
  249. protected override void OnMouseUp(MouseEventArgs mevent)
  250. {
  251. base.OnMouseUp(mevent);
  252. this.MouseState = EMouseState.Up;
  253. }
  254. }
  255. }