// *********************************************************************** // Assembly : HZH_Controls // Created : 08-08-2019 // // *********************************************************************** // // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com // // // Blog: https://www.cnblogs.com/bfyx // GitHub:https://github.com/kwwwvagaa/NetWinformControl // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git // // If you use this code, please keep this note. // *********************************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace HZH_Controls.Controls { /// /// Class UCCheckBox. /// Implements the /// /// [DefaultEvent("CheckedChangeEvent")] public partial class UCCheckBox : UserControl { /// /// 选中改变事件 /// [Description("选中改变事件"), Category("自定义")] public event EventHandler CheckedChangeEvent; /// /// 字体 /// /// The font. /// /// /// /// /// /// [Description("字体"), Category("自定义")] public override Font Font { get { return base.Font; } set { base.Font = value; label1.Font = value; } } /// /// The fore color /// private Color _ForeColor = Color.FromArgb(62, 62, 62); /// /// 字体颜色 /// /// The color of the fore. /// /// /// [Description("字体颜色"), Category("自定义")] public new Color ForeColor { get { return _ForeColor; } set { base.ForeColor = value; label1.ForeColor = value; _ForeColor = value; } } /// /// The text /// private string _Text = "复选框"; /// /// 文本 /// /// The text value. [Description("文本"), Category("自定义")] public string TextValue { get { return _Text; } set { label1.Text = value; _Text = value; } } /// /// The checked /// private bool _checked = false; /// /// 是否选中 /// /// true if checked; otherwise, false. [Description("是否选中"), Category("自定义")] public bool Checked { get { return _checked; } set { if (_checked != value) { _checked = value; if (base.Enabled) { if (_checked) { panel1.BackgroundImage = Properties.Resources.checkbox1; } else { panel1.BackgroundImage = Properties.Resources.checkbox0; } } else { if (_checked) { panel1.BackgroundImage = Properties.Resources.checkbox10; } else { panel1.BackgroundImage = Properties.Resources.checkbox00; } } if (CheckedChangeEvent != null) { CheckedChangeEvent(this, null); } } } } /// /// 获取或设置一个值,该值指示控件是否可以对用户交互作出响应。 /// /// true if enabled; otherwise, false. /// /// /// /// /// /// public new bool Enabled { get { return base.Enabled; } set { base.Enabled = value; if (value) { if (_checked) { panel1.BackgroundImage = Properties.Resources.checkbox1; } else { panel1.BackgroundImage = Properties.Resources.checkbox0; } } else { if (_checked) { panel1.BackgroundImage = Properties.Resources.checkbox10; } else { panel1.BackgroundImage = Properties.Resources.checkbox00; } } } } /// /// Initializes a new instance of the class. /// public UCCheckBox() { InitializeComponent(); } /// /// Handles the MouseDown event of the CheckBox control. /// /// The source of the event. /// The instance containing the event data. private void CheckBox_MouseDown(object sender, MouseEventArgs e) { Checked = !Checked; } } }