using System;
using System.Drawing;
using System.ComponentModel;
using FastReport.Utils;
using System.Windows.Forms;
namespace FastReport.Dialog
{
///
/// Represents a Windows CheckBox.
/// Wraps the control.
///
public partial class CheckBoxControl : ButtonBaseControl
{
#region Fields
private CheckBox checkBox;
private string checkedChangedEvent;
#endregion
#region Properties
///
/// Occurs when the value of the Checked property changes.
/// Wraps the event.
///
public event EventHandler CheckedChanged;
///
/// Gets an internal CheckBox.
///
[Browsable(false)]
public CheckBox CheckBox
{
get { return checkBox; }
}
///
/// Gets or sets the value that determines the appearance of a CheckBox control.
/// Wraps the property.
///
[DefaultValue(Appearance.Normal)]
[Category("Appearance")]
public Appearance Appearance
{
get { return CheckBox.Appearance; }
set { CheckBox.Appearance = value; }
}
///
/// Gets or sets the horizontal and vertical alignment of the check mark on a CheckBox control.
/// Wraps the property.
///
[DefaultValue(ContentAlignment.MiddleLeft)]
[Category("Appearance")]
public ContentAlignment CheckAlign
{
get { return CheckBox.CheckAlign; }
set { CheckBox.CheckAlign = value; }
}
///
/// Gets or set a value indicating whether the CheckBox is in the checked state.
/// Wraps the property.
///
[DefaultValue(false)]
[Category("Appearance")]
public bool Checked
{
get { return CheckBox.Checked; }
set { CheckBox.Checked = value; }
}
///
/// Gets or sets the state of the CheckBox.
/// Wraps the property.
///
[DefaultValue(CheckState.Unchecked)]
[Category("Appearance")]
public CheckState CheckState
{
get { return CheckBox.CheckState; }
set { CheckBox.CheckState = value; }
}
///
/// Gets or sets a value indicating whether the CheckBox will allow three check states rather than two.
/// Wraps the property.
///
[DefaultValue(false)]
[Category("Appearance")]
public bool ThreeState
{
get { return CheckBox.ThreeState; }
set { CheckBox.ThreeState = 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 CheckBox_CheckedChanged(object sender, EventArgs e)
{
OnCheckedChanged(e);
}
#endregion
#region Protected Methods
///
protected override void AttachEvents()
{
base.AttachEvents();
CheckBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
}
///
protected override void DetachEvents()
{
base.DetachEvents();
CheckBox.CheckedChanged -= new EventHandler(CheckBox_CheckedChanged);
}
///
protected override object GetValue()
{
return Checked;
}
#endregion
#region Public Methods
///
public override void Serialize(FRWriter writer)
{
CheckBoxControl c = writer.DiffObject as CheckBoxControl;
base.Serialize(writer);
if (Appearance != c.Appearance)
writer.WriteValue("Appearance", Appearance);
if (CheckAlign != c.CheckAlign)
writer.WriteValue("CheckAlign", CheckAlign);
if (Checked != c.Checked)
writer.WriteBool("Checked", Checked);
if (CheckState != c.CheckState)
writer.WriteValue("CheckState", CheckState);
if (ThreeState != c.ThreeState)
writer.WriteBool("ThreeState", ThreeState);
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 CheckBoxControl class with default settings.
///
public CheckBoxControl()
{
checkBox = new CheckBox();
Control = checkBox;
CheckBox.AutoSize = true;
BindableProperty = this.GetType().GetProperty("Checked");
}
}
}