2021-07-22 23:45:30 +00:00
|
|
|
|
namespace RyzStudio.Windows.ThemedForms
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
public partial class TButton : RyzStudio.Windows.ThemedForms.TUserControl
|
|
|
|
|
{
|
|
|
|
|
public class ButtonStyle
|
|
|
|
|
{
|
|
|
|
|
public Color BackColour { get; set; } = Color.Transparent;
|
|
|
|
|
public Color PenColour { get; set; } = Color.Transparent;
|
|
|
|
|
public Image ForeImage { get; set; } = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ButtonState
|
|
|
|
|
{
|
|
|
|
|
Idle = 0,
|
|
|
|
|
Hover,
|
|
|
|
|
Down
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ButtonState controlState = ButtonState.Idle;
|
|
|
|
|
protected bool isSelected = false;
|
|
|
|
|
|
|
|
|
|
public TButton() : base()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
this.Margin = new Padding(10);
|
|
|
|
|
|
|
|
|
|
this.StyleDefault = new ButtonStyle()
|
|
|
|
|
{
|
|
|
|
|
BackColour = Color.White,
|
|
|
|
|
PenColour = Color.Black,
|
|
|
|
|
ForeImage = this.DefaultImage
|
|
|
|
|
};
|
|
|
|
|
this.StyleDown = new ButtonStyle()
|
|
|
|
|
{
|
2021-07-24 21:46:01 +00:00
|
|
|
|
BackColour = Color.FromArgb(60, 53, 148),
|
2021-07-24 21:15:55 +00:00
|
|
|
|
PenColour = Color.White,
|
2021-07-22 23:45:30 +00:00
|
|
|
|
ForeImage = this.DownImage
|
|
|
|
|
};
|
|
|
|
|
this.StyleOver = new ButtonStyle()
|
|
|
|
|
{
|
|
|
|
|
BackColour = Color.FromArgb(108, 101, 196),
|
|
|
|
|
PenColour = Color.White,
|
|
|
|
|
ForeImage = this.OverImage
|
|
|
|
|
};
|
|
|
|
|
this.StyleSelected = new ButtonStyle()
|
|
|
|
|
{
|
|
|
|
|
BackColour = Color.FromArgb(51, 51, 51),
|
|
|
|
|
PenColour = Color.White,
|
|
|
|
|
ForeImage = this.OverImage
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
label1.ImageAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
label1.Click += delegate { this.OnClick(null); };
|
|
|
|
|
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; };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
this.VisualState = ButtonState.Idle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
|
public new Padding Margin { get => base.Margin; set => base.Margin = value; }
|
|
|
|
|
|
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
|
public new Padding Padding { get => base.Padding; set => base.Padding = value; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected ButtonState VisualState
|
|
|
|
|
{
|
|
|
|
|
get { return controlState; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
switch (value)
|
|
|
|
|
{
|
|
|
|
|
case ButtonState.Idle:
|
|
|
|
|
if (this.VisualState == ButtonState.Down)
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleOver);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (this.IsSelected)
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleSelected);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleDefault);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case ButtonState.Hover:
|
|
|
|
|
updateButton(StyleOver);
|
|
|
|
|
break;
|
|
|
|
|
case ButtonState.Down:
|
|
|
|
|
updateButton(StyleDown);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (this.IsSelected)
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleSelected);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleDefault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controlState = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void updateButton(ButtonStyle 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;
|
|
|
|
|
|
|
|
|
|
public bool IsSelected
|
|
|
|
|
{
|
|
|
|
|
get => isSelected;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
isSelected = value;
|
|
|
|
|
|
|
|
|
|
this.VisualState = this.VisualState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
public void PerformClick() => this.OnClick(null);
|
|
|
|
|
}
|
|
|
|
|
}
|