ChkCheckBox.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace Dongke.WinForm.Controls
  6. {
  7. /// <summary>
  8. /// 标准多选按钮
  9. /// </summary>
  10. [ToolboxBitmap(typeof(CheckBox))]
  11. public class ChkCheckBox : CheckBox, IDKControl, IAsyncControl
  12. {
  13. #region 构造函数
  14. /// <summary>
  15. /// 标准单选按钮
  16. /// </summary>
  17. public ChkCheckBox()
  18. {
  19. base.AutoSize = true;
  20. this.BackColor = Color.Transparent;
  21. }
  22. #endregion
  23. #region 重写属性
  24. /// <summary>
  25. /// 获取或设置一个值,该值指示是否自动调整控件的大小以完整显示其内容
  26. /// </summary>
  27. [DefaultValue(true)]
  28. public override bool AutoSize
  29. {
  30. get
  31. {
  32. return base.AutoSize;
  33. }
  34. set
  35. {
  36. base.AutoSize = value;
  37. }
  38. }
  39. /// <summary>
  40. /// 获取或设置控件的背景色
  41. /// </summary>
  42. [DefaultValue(typeof(Color), "Transparent")]
  43. public override Color BackColor
  44. {
  45. get
  46. {
  47. return base.BackColor;
  48. }
  49. set
  50. {
  51. base.BackColor = value;
  52. }
  53. }
  54. #endregion
  55. #region IAsyncControl 成员
  56. #region 成员变量
  57. /// <summary>
  58. /// 异步处理开始时,控件状态
  59. /// </summary>
  60. private bool _asyncBeginStatus = false;
  61. private bool _asyncBeginFocused = false;
  62. #endregion
  63. #region 公有方法
  64. /// <summary>
  65. /// 开始异步处理
  66. /// </summary>
  67. /// <param name="doFocus">是否处理焦点</param>
  68. public virtual void BeginAsync(ref bool doFocus)
  69. {
  70. this._asyncBeginFocused = false;
  71. if (doFocus && this.Focused)
  72. {
  73. this._asyncBeginFocused = true;
  74. doFocus = false;
  75. }
  76. this._asyncBeginStatus = this.Enabled;
  77. this.Enabled = false;
  78. }
  79. /// <summary>
  80. /// 结束异步处理
  81. /// </summary>
  82. public virtual void EndAsync()
  83. {
  84. this.Enabled = this._asyncBeginStatus;
  85. if (this._asyncBeginFocused)
  86. {
  87. this.Focus();
  88. }
  89. }
  90. #endregion
  91. #endregion
  92. }
  93. }