2021-09-07 11:32:24 +00:00
|
|
|
|
namespace RyzStudio.Windows.ThemedForms
|
|
|
|
|
{
|
2021-09-30 21:26:17 +00:00
|
|
|
|
using RyzStudio.Windows.Forms;
|
2021-09-07 11:32:24 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
BackColour = Color.FromArgb(60, 53, 148),
|
|
|
|
|
PenColour = Color.White,
|
|
|
|
|
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;
|
2021-09-12 14:25:37 +00:00
|
|
|
|
label1.Click += label1_Click;
|
|
|
|
|
label1.MouseClick += label1_MouseClick;
|
|
|
|
|
label1.MouseEnter += delegate { this.VisualState = ButtonState.Hover; };
|
2021-09-07 11:32:24 +00:00
|
|
|
|
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")]
|
2021-09-30 21:26:17 +00:00
|
|
|
|
public string LabelText { get => ThreadControl.GetText(label1); set => ThreadControl.SetText(label1, value); }
|
2021-09-07 11:32:24 +00:00
|
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 14:25:37 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
protected ButtonStyle StyleOver { get; set; } = new ButtonStyle();
|
2021-09-12 14:25:37 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
protected ButtonStyle StyleDown { get; set; } = new ButtonStyle();
|
2021-09-12 14:25:37 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
protected ButtonStyle StyleDefault { get; set; } = new ButtonStyle();
|
2021-09-12 14:25:37 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
protected ButtonStyle StyleSelected { get; set; } = new ButtonStyle();
|
|
|
|
|
|
2021-09-12 14:25:37 +00:00
|
|
|
|
|
|
|
|
|
private void label1_MouseClick(object sender, MouseEventArgs e) => this.OnMouseClick(e);
|
|
|
|
|
|
|
|
|
|
private void label1_Click(object sender, EventArgs e) => this.OnClick(e);
|
|
|
|
|
|
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
public void PerformClick() => this.OnClick(null);
|
2021-09-12 14:25:37 +00:00
|
|
|
|
|
2021-09-07 11:32:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|