CheckBoxControl.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Drawing;
  3. using System.ComponentModel;
  4. using FastReport.Utils;
  5. using System.Windows.Forms;
  6. namespace FastReport.Dialog
  7. {
  8. /// <summary>
  9. /// Represents a Windows CheckBox.
  10. /// Wraps the <see cref="System.Windows.Forms.CheckBox"/> control.
  11. /// </summary>
  12. public partial class CheckBoxControl : ButtonBaseControl
  13. {
  14. #region Fields
  15. private CheckBox checkBox;
  16. private string checkedChangedEvent;
  17. #endregion
  18. #region Properties
  19. /// <summary>
  20. /// Occurs when the value of the <b>Checked</b> property changes.
  21. /// Wraps the <see cref="System.Windows.Forms.CheckBox.CheckedChanged"/> event.
  22. /// </summary>
  23. public event EventHandler CheckedChanged;
  24. /// <summary>
  25. /// Gets an internal <b>CheckBox</b>.
  26. /// </summary>
  27. [Browsable(false)]
  28. public CheckBox CheckBox
  29. {
  30. get { return checkBox; }
  31. }
  32. /// <summary>
  33. /// Gets or sets the value that determines the appearance of a CheckBox control.
  34. /// Wraps the <see cref="System.Windows.Forms.CheckBox.Appearance"/> property.
  35. /// </summary>
  36. [DefaultValue(Appearance.Normal)]
  37. [Category("Appearance")]
  38. public Appearance Appearance
  39. {
  40. get { return CheckBox.Appearance; }
  41. set { CheckBox.Appearance = value; }
  42. }
  43. /// <summary>
  44. /// Gets or sets the horizontal and vertical alignment of the check mark on a CheckBox control.
  45. /// Wraps the <see cref="System.Windows.Forms.CheckBox.CheckAlign"/> property.
  46. /// </summary>
  47. [DefaultValue(ContentAlignment.MiddleLeft)]
  48. [Category("Appearance")]
  49. public ContentAlignment CheckAlign
  50. {
  51. get { return CheckBox.CheckAlign; }
  52. set { CheckBox.CheckAlign = value; }
  53. }
  54. /// <summary>
  55. /// Gets or set a value indicating whether the CheckBox is in the checked state.
  56. /// Wraps the <see cref="System.Windows.Forms.CheckBox.Checked"/> property.
  57. /// </summary>
  58. [DefaultValue(false)]
  59. [Category("Appearance")]
  60. public bool Checked
  61. {
  62. get { return CheckBox.Checked; }
  63. set { CheckBox.Checked = value; }
  64. }
  65. /// <summary>
  66. /// Gets or sets the state of the CheckBox.
  67. /// Wraps the <see cref="System.Windows.Forms.CheckBox.CheckState"/> property.
  68. /// </summary>
  69. [DefaultValue(CheckState.Unchecked)]
  70. [Category("Appearance")]
  71. public CheckState CheckState
  72. {
  73. get { return CheckBox.CheckState; }
  74. set { CheckBox.CheckState = value; }
  75. }
  76. /// <summary>
  77. /// Gets or sets a value indicating whether the CheckBox will allow three check states rather than two.
  78. /// Wraps the <see cref="System.Windows.Forms.CheckBox.ThreeState"/> property.
  79. /// </summary>
  80. [DefaultValue(false)]
  81. [Category("Appearance")]
  82. public bool ThreeState
  83. {
  84. get { return CheckBox.ThreeState; }
  85. set { CheckBox.ThreeState = value; }
  86. }
  87. /// <summary>
  88. /// Gets or sets a script method name that will be used to handle the
  89. /// <see cref="CheckedChanged"/> event.
  90. /// </summary>
  91. [Category("Events")]
  92. public string CheckedChangedEvent
  93. {
  94. get { return checkedChangedEvent; }
  95. set { checkedChangedEvent = value; }
  96. }
  97. #endregion
  98. #region Private Methods
  99. private void CheckBox_CheckedChanged(object sender, EventArgs e)
  100. {
  101. OnCheckedChanged(e);
  102. }
  103. #endregion
  104. #region Protected Methods
  105. /// <inheritdoc/>
  106. protected override void AttachEvents()
  107. {
  108. base.AttachEvents();
  109. CheckBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
  110. }
  111. /// <inheritdoc/>
  112. protected override void DetachEvents()
  113. {
  114. base.DetachEvents();
  115. CheckBox.CheckedChanged -= new EventHandler(CheckBox_CheckedChanged);
  116. }
  117. /// <inheritdoc/>
  118. protected override object GetValue()
  119. {
  120. return Checked;
  121. }
  122. #endregion
  123. #region Public Methods
  124. /// <inheritdoc/>
  125. public override void Serialize(FRWriter writer)
  126. {
  127. CheckBoxControl c = writer.DiffObject as CheckBoxControl;
  128. base.Serialize(writer);
  129. if (Appearance != c.Appearance)
  130. writer.WriteValue("Appearance", Appearance);
  131. if (CheckAlign != c.CheckAlign)
  132. writer.WriteValue("CheckAlign", CheckAlign);
  133. if (Checked != c.Checked)
  134. writer.WriteBool("Checked", Checked);
  135. if (CheckState != c.CheckState)
  136. writer.WriteValue("CheckState", CheckState);
  137. if (ThreeState != c.ThreeState)
  138. writer.WriteBool("ThreeState", ThreeState);
  139. if (CheckedChangedEvent != c.CheckedChangedEvent)
  140. writer.WriteStr("CheckedChangedEvent", CheckedChangedEvent);
  141. }
  142. /// <summary>
  143. /// This method fires the <b>CheckedChanged</b> event and the script code connected to the <b>CheckedChangedEvent</b>.
  144. /// </summary>
  145. /// <param name="e">Event data.</param>
  146. public virtual void OnCheckedChanged(EventArgs e)
  147. {
  148. OnFilterChanged();
  149. if (CheckedChanged != null)
  150. CheckedChanged(this, e);
  151. InvokeEvent(CheckedChangedEvent, e);
  152. }
  153. #endregion
  154. /// <summary>
  155. /// Initializes a new instance of the <b>CheckBoxControl</b> class with default settings.
  156. /// </summary>
  157. public CheckBoxControl()
  158. {
  159. checkBox = new CheckBox();
  160. Control = checkBox;
  161. CheckBox.AutoSize = true;
  162. BindableProperty = this.GetType().GetProperty("Checked");
  163. }
  164. }
  165. }