RadioButtonControl.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /// Enables the user to select a single option from a group of choices when paired with other RadioButton controls.
  10. /// Wraps the <see cref="System.Windows.Forms.RadioButton"/> control.
  11. /// </summary>
  12. public partial class RadioButtonControl : ButtonBaseControl
  13. {
  14. private RadioButton radioButton;
  15. private string checkedChangedEvent;
  16. #region Properties
  17. /// <summary>
  18. /// Occurs when the value of the Checked property changes.
  19. /// Wraps the <see cref="System.Windows.Forms.RadioButton.CheckedChanged"/> event.
  20. /// </summary>
  21. public event EventHandler CheckedChanged;
  22. /// <summary>
  23. /// Gets an internal <b>RadioButton</b>.
  24. /// </summary>
  25. [Browsable(false)]
  26. public RadioButton RadioButton
  27. {
  28. get { return radioButton; }
  29. }
  30. /// <summary>
  31. /// Gets or sets the location of the check box portion of the RadioButton.
  32. /// Wraps the <see cref="System.Windows.Forms.RadioButton.CheckAlign"/> property.
  33. /// </summary>
  34. [DefaultValue(ContentAlignment.MiddleLeft)]
  35. [Category("Appearance")]
  36. public ContentAlignment CheckAlign
  37. {
  38. get { return RadioButton.CheckAlign; }
  39. set { RadioButton.CheckAlign = value; }
  40. }
  41. /// <summary>
  42. /// Gets or sets a value indicating whether the control is checked.
  43. /// Wraps the <see cref="System.Windows.Forms.RadioButton.Checked"/> property.
  44. /// </summary>
  45. [DefaultValue(false)]
  46. [Category("Appearance")]
  47. public bool Checked
  48. {
  49. get { return RadioButton.Checked; }
  50. set { RadioButton.Checked = value; }
  51. }
  52. /// <summary>
  53. /// Gets or sets a script method name that will be used to handle the
  54. /// <see cref="CheckedChanged"/> event.
  55. /// </summary>
  56. [Category("Events")]
  57. public string CheckedChangedEvent
  58. {
  59. get { return checkedChangedEvent; }
  60. set { checkedChangedEvent = value; }
  61. }
  62. #endregion
  63. #region Private Methods
  64. private void RadioButton_CheckedChanged(object sender, EventArgs e)
  65. {
  66. OnCheckedChanged(e);
  67. }
  68. #endregion
  69. #region Protected Methods
  70. /// <inheritdoc/>
  71. protected override void AttachEvents()
  72. {
  73. base.AttachEvents();
  74. RadioButton.CheckedChanged += new EventHandler(RadioButton_CheckedChanged);
  75. }
  76. /// <inheritdoc/>
  77. protected override void DetachEvents()
  78. {
  79. base.DetachEvents();
  80. RadioButton.CheckedChanged -= new EventHandler(RadioButton_CheckedChanged);
  81. }
  82. /// <inheritdoc/>
  83. protected override object GetValue()
  84. {
  85. return Checked;
  86. }
  87. #endregion
  88. #region Public Methods
  89. /// <inheritdoc/>
  90. public override void Serialize(FRWriter writer)
  91. {
  92. RadioButtonControl c = writer.DiffObject as RadioButtonControl;
  93. base.Serialize(writer);
  94. if (CheckAlign != c.CheckAlign)
  95. writer.WriteValue("CheckAlign", CheckAlign);
  96. if (Checked != c.Checked)
  97. writer.WriteBool("Checked", Checked);
  98. if (CheckedChangedEvent != c.CheckedChangedEvent)
  99. writer.WriteStr("CheckedChangedEvent", CheckedChangedEvent);
  100. }
  101. /// <summary>
  102. /// This method fires the <b>CheckedChanged</b> event and the script code connected to the <b>CheckedChangedEvent</b>.
  103. /// </summary>
  104. /// <param name="e">Event data.</param>
  105. public virtual void OnCheckedChanged(EventArgs e)
  106. {
  107. OnFilterChanged();
  108. if (CheckedChanged != null)
  109. CheckedChanged(this, e);
  110. InvokeEvent(CheckedChangedEvent, e);
  111. }
  112. #endregion
  113. /// <summary>
  114. /// Initializes a new instance of the <b>RadioButtonControl</b> class with default settings.
  115. /// </summary>
  116. public RadioButtonControl()
  117. {
  118. radioButton = new RadioButton();
  119. Control = radioButton;
  120. RadioButton.AutoSize = true;
  121. RadioButton.TabStop = true;
  122. BindableProperty = this.GetType().GetProperty("Checked");
  123. }
  124. }
  125. }