using System; using System.Drawing; using System.ComponentModel; using FastReport.Utils; using System.Windows.Forms; namespace FastReport.Dialog { /// /// Enables the user to select a single option from a group of choices when paired with other RadioButton controls. /// Wraps the control. /// public partial class RadioButtonControl : ButtonBaseControl { private RadioButton radioButton; private string checkedChangedEvent; #region Properties /// /// Occurs when the value of the Checked property changes. /// Wraps the event. /// public event EventHandler CheckedChanged; /// /// Gets an internal RadioButton. /// [Browsable(false)] public RadioButton RadioButton { get { return radioButton; } } /// /// Gets or sets the location of the check box portion of the RadioButton. /// Wraps the property. /// [DefaultValue(ContentAlignment.MiddleLeft)] [Category("Appearance")] public ContentAlignment CheckAlign { get { return RadioButton.CheckAlign; } set { RadioButton.CheckAlign = value; } } /// /// Gets or sets a value indicating whether the control is checked. /// Wraps the property. /// [DefaultValue(false)] [Category("Appearance")] public bool Checked { get { return RadioButton.Checked; } set { RadioButton.Checked = value; } } /// /// Gets or sets a script method name that will be used to handle the /// event. /// [Category("Events")] public string CheckedChangedEvent { get { return checkedChangedEvent; } set { checkedChangedEvent = value; } } #endregion #region Private Methods private void RadioButton_CheckedChanged(object sender, EventArgs e) { OnCheckedChanged(e); } #endregion #region Protected Methods /// protected override void AttachEvents() { base.AttachEvents(); RadioButton.CheckedChanged += new EventHandler(RadioButton_CheckedChanged); } /// protected override void DetachEvents() { base.DetachEvents(); RadioButton.CheckedChanged -= new EventHandler(RadioButton_CheckedChanged); } /// protected override object GetValue() { return Checked; } #endregion #region Public Methods /// public override void Serialize(FRWriter writer) { RadioButtonControl c = writer.DiffObject as RadioButtonControl; base.Serialize(writer); if (CheckAlign != c.CheckAlign) writer.WriteValue("CheckAlign", CheckAlign); if (Checked != c.Checked) writer.WriteBool("Checked", Checked); if (CheckedChangedEvent != c.CheckedChangedEvent) writer.WriteStr("CheckedChangedEvent", CheckedChangedEvent); } /// /// This method fires the CheckedChanged event and the script code connected to the CheckedChangedEvent. /// /// Event data. public virtual void OnCheckedChanged(EventArgs e) { OnFilterChanged(); if (CheckedChanged != null) CheckedChanged(this, e); InvokeEvent(CheckedChangedEvent, e); } #endregion /// /// Initializes a new instance of the RadioButtonControl class with default settings. /// public RadioButtonControl() { radioButton = new RadioButton(); Control = radioButton; RadioButton.AutoSize = true; RadioButton.TabStop = true; BindableProperty = this.GetType().GetProperty("Checked"); } } }