namespace RyzStudio.Windows.ThemedForms { using System; using System.ComponentModel; using System.Drawing; public partial class TButton : RyzStudio.Windows.ThemedForms.TUserControl { public class Style { public Color BackColour { get; set; } = Color.Transparent; public Color PenColour { get; set; } = Color.Transparent; public Image ForeImage { get; set; } = null; } public enum State { Idle = 0, Hover, Down } protected State controlState = State.Idle; public TButton() : base() { InitializeComponent(); label1.ImageAlign = ContentAlignment.MiddleCenter; label1.Click += delegate { this.OnClick(null); }; label1.MouseEnter += delegate { this.VisualState = State.Hover; }; label1.MouseLeave += delegate { this.VisualState = State.Idle; }; label1.MouseDown += delegate { this.VisualState = State.Down; }; label1.MouseUp += delegate { this.VisualState = State.Idle; }; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); // customise this.StyleOver = new Style() { BackColour = Color.FromArgb(51, 51, 51), PenColour = Color.White, ForeImage = this.OverImage }; this.StyleDown = new Style() { BackColour = Color.FromArgb(179, 179, 179), PenColour = Color.Black, ForeImage = this.DownImage }; this.StyleDefault = new Style() { BackColour = Color.White, PenColour = Color.Black, ForeImage = this.DefaultImage }; this.VisualState = State.Idle; } protected State VisualState { get { return controlState; } set { switch (value) { case State.Idle: if (this.VisualState == State.Down) { updateButton(StyleOver); } else { updateButton(StyleDefault); } break; case State.Hover: updateButton(StyleOver); break; case State.Down: updateButton(StyleDown); break; default: updateButton(StyleDefault); break; } controlState = value; } } protected void updateButton(Style style) { label1.ForeColor = style.PenColour; label1.BackColor = style.BackColour; label1.Image = style.ForeImage; } [Browsable(true)] [Category("Appearance")] public string LabelText { get => label1.Text; set => label1.Text = value; } [Browsable(true)] [Category("Appearance")] public Image OverImage { get; set; } = null; [Browsable(true)] [Category("Appearance")] public Image DownImage { get; set; } = null; [Browsable(true)] [Category("Appearance")] public Image DefaultImage { get; set; } = null; [Browsable(false)] public Style StyleOver { get; set; } = new Style(); [Browsable(false)] public Style StyleDown { get; set; } = new Style(); [Browsable(false)] public Style StyleDefault { get; set; } = new Style(); public void PerformClick() => this.OnClick(null); } }