2020-04-27 12:17:13 +00:00
|
|
|
|
namespace RyzStudio.Windows.ThemedForms
|
|
|
|
|
{
|
2020-05-07 22:31:03 +00:00
|
|
|
|
using System;
|
2020-05-10 10:03:55 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-10 10:45:54 +00:00
|
|
|
|
public partial class TButton : RyzStudio.Windows.ThemedForms.TUserControl
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public class ButtonStyle
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
public Color BackColour { get; set; } = Color.Transparent;
|
|
|
|
|
public Color PenColour { get; set; } = Color.Transparent;
|
|
|
|
|
public Image ForeImage { get; set; } = null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public enum ButtonState
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
Idle = 0,
|
|
|
|
|
Hover,
|
|
|
|
|
Down
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
protected ButtonState controlState = ButtonState.Idle;
|
2020-05-17 11:28:21 +00:00
|
|
|
|
protected bool isSelected = false;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-17 11:28:21 +00:00
|
|
|
|
public TButton() : base()
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
label1.ImageAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
|
2020-05-17 11:28:21 +00:00
|
|
|
|
this.StyleDefault = new ButtonStyle() { BackColour = Color.White, PenColour = Color.Black, ForeImage = this.DefaultImage };
|
|
|
|
|
this.StyleDown = new ButtonStyle() { BackColour = Color.FromArgb(179, 179, 179), PenColour = Color.Black, ForeImage = this.DownImage };
|
|
|
|
|
this.StyleOver = new ButtonStyle() { BackColour = Color.FromArgb(51, 51, 51), PenColour = Color.White, ForeImage = this.OverImage };
|
|
|
|
|
this.StyleSelected = new ButtonStyle() { BackColour = Color.FromArgb(51, 51, 51), PenColour = Color.White, ForeImage = this.OverImage };
|
|
|
|
|
|
|
|
|
|
label1.Click += delegate { this.OnClick(null); };
|
2020-05-12 23:37:01 +00:00
|
|
|
|
label1.MouseEnter += delegate { this.VisualState = ButtonState.Hover; };
|
|
|
|
|
label1.MouseLeave += delegate { this.VisualState = ButtonState.Idle; };
|
|
|
|
|
label1.MouseDown += delegate { this.VisualState = ButtonState.Down; };
|
|
|
|
|
label1.MouseUp += delegate { this.VisualState = ButtonState.Idle; };
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 10:03:55 +00:00
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
this.VisualState = ButtonState.Idle;
|
2020-05-07 22:31:03 +00:00
|
|
|
|
}
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
protected ButtonState VisualState
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
2020-05-10 10:03:55 +00:00
|
|
|
|
get { return controlState; }
|
2020-04-27 12:17:13 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
switch (value)
|
|
|
|
|
{
|
2020-05-12 23:37:01 +00:00
|
|
|
|
case ButtonState.Idle:
|
|
|
|
|
if (this.VisualState == ButtonState.Down)
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
|
|
|
|
updateButton(StyleOver);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-17 11:28:21 +00:00
|
|
|
|
if (this.IsSelected)
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleSelected);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleDefault);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
|
|
|
|
break;
|
2020-05-12 23:37:01 +00:00
|
|
|
|
case ButtonState.Hover:
|
2020-04-27 12:17:13 +00:00
|
|
|
|
updateButton(StyleOver);
|
|
|
|
|
break;
|
2020-05-12 23:37:01 +00:00
|
|
|
|
case ButtonState.Down:
|
2020-04-27 12:17:13 +00:00
|
|
|
|
updateButton(StyleDown);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-05-17 11:28:21 +00:00
|
|
|
|
if (this.IsSelected)
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleSelected);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleDefault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 10:03:55 +00:00
|
|
|
|
controlState = value;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
protected void updateButton(ButtonStyle style)
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
|
|
|
|
label1.ForeColor = style.PenColour;
|
|
|
|
|
label1.BackColor = style.BackColour;
|
|
|
|
|
label1.Image = style.ForeImage;
|
2020-05-07 22:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(true)]
|
2020-04-27 12:17:13 +00:00
|
|
|
|
[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;
|
|
|
|
|
|
2020-05-17 11:28:21 +00:00
|
|
|
|
public bool IsSelected
|
|
|
|
|
{
|
|
|
|
|
get => isSelected;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
isSelected = value;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-17 11:28:21 +00:00
|
|
|
|
this.VisualState = this.VisualState;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-17 11:28:21 +00:00
|
|
|
|
protected ButtonStyle StyleOver { get; set; } = new ButtonStyle();
|
|
|
|
|
protected ButtonStyle StyleDown { get; set; } = new ButtonStyle();
|
|
|
|
|
protected ButtonStyle StyleDefault { get; set; } = new ButtonStyle();
|
|
|
|
|
protected ButtonStyle StyleSelected { get; set; } = new ButtonStyle();
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
|
|
|
|
public void PerformClick() => this.OnClick(null);
|
|
|
|
|
}
|
|
|
|
|
}
|