This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
gwen-dotnet/Gwen/Control/Property/Check.cs
Gered 10e057953e initial commit
Contains changes from "gwen-dotnet" removing dependancies on Windows,
which ultimately means certain features (e.g. file load/save dialogs)
do not work. Those classes still exist, but the code has been commented
out.
2013-03-28 18:47:01 -04:00

72 lines
2 KiB
C#

using System;
namespace Gwen.Control.Property
{
/// <summary>
/// Checkable property.
/// </summary>
public class Check : Base
{
protected readonly Control.CheckBox m_CheckBox;
/// <summary>
/// Initializes a new instance of the <see cref="Check"/> class.
/// </summary>
/// <param name="parent">Parent control.</param>
public Check(Control.Base parent)
: base(parent)
{
m_CheckBox = new Control.CheckBox(this);
m_CheckBox.ShouldDrawBackground = false;
m_CheckBox.CheckChanged += OnValueChanged;
m_CheckBox.IsTabable = true;
m_CheckBox.KeyboardInputEnabled = true;
m_CheckBox.SetPosition(2, 1);
Height = 18;
}
/// <summary>
/// Property value.
/// </summary>
public override string Value
{
get { return m_CheckBox.IsChecked ? "1" : "0"; }
set { base.Value = value; }
}
/// <summary>
/// Sets the property value.
/// </summary>
/// <param name="value">Value to set.</param>
/// <param name="fireEvents">Determines whether to fire "value changed" event.</param>
public override void SetValue(string value, bool fireEvents = false)
{
if (value == "1" || value.ToLower() == "true" || value.ToLower() == "yes")
{
m_CheckBox.IsChecked = true;
}
else
{
m_CheckBox.IsChecked = false;
}
}
/// <summary>
/// Indicates whether the property value is being edited.
/// </summary>
public override bool IsEditing
{
get { return m_CheckBox.HasFocus; }
}
/// <summary>
/// Indicates whether the control is hovered by mouse pointer.
/// </summary>
public override bool IsHovered
{
get { return base.IsHovered || m_CheckBox.IsHovered; }
}
}
}