106 lines
2.5 KiB
C#
106 lines
2.5 KiB
C#
namespace RyzStudio.Windows.ThemedForms
|
|
{
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
|
|
public partial class Button : RyzStudio.Windows.ThemedForms.UserControl
|
|
{
|
|
protected ButtonState buttonState = ButtonState.Normal;
|
|
|
|
public Button() : base()
|
|
{
|
|
InitializeComponent();
|
|
|
|
label1.ImageAlign = ContentAlignment.MiddleCenter;
|
|
|
|
label1.Click += delegate { this.OnClick(null); };
|
|
label1.MouseEnter += delegate { this.VisualState = ButtonState.Hover; };
|
|
label1.MouseLeave += delegate { this.VisualState = ButtonState.Normal; };
|
|
label1.MouseDown += delegate { this.VisualState = ButtonState.Down; };
|
|
label1.MouseUp += delegate { this.VisualState = ButtonState.Normal; };
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
this.StyleOver.ForeImage = this.OverImage;
|
|
this.StyleDown.ForeImage = this.DownImage;
|
|
this.StyleDefault.ForeImage = this.DefaultImage;
|
|
|
|
this.VisualState = ButtonState.Normal;
|
|
}
|
|
|
|
protected ButtonState VisualState
|
|
{
|
|
get { return buttonState; }
|
|
set
|
|
{
|
|
switch (value)
|
|
{
|
|
case ButtonState.Normal:
|
|
if (this.VisualState == ButtonState.Down)
|
|
{
|
|
updateButton(StyleOver);
|
|
}
|
|
else
|
|
{
|
|
updateButton(StyleDefault);
|
|
}
|
|
|
|
break;
|
|
case ButtonState.Hover:
|
|
updateButton(StyleOver);
|
|
break;
|
|
case ButtonState.Down:
|
|
updateButton(StyleDown);
|
|
break;
|
|
default:
|
|
updateButton(StyleDefault);
|
|
break;
|
|
}
|
|
|
|
buttonState = 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;
|
|
|
|
[Browsable(false)]
|
|
public ButtonStyle StyleOver { get; set; } = new ButtonStyle(Color.Black, Color.White);
|
|
|
|
[Browsable(false)]
|
|
public ButtonStyle StyleDown { get; set; } = new ButtonStyle(Color.LightGray, Color.Black);
|
|
|
|
[Browsable(false)]
|
|
public ButtonStyle StyleDefault { get; set; } = new ButtonStyle(Color.White, Color.Black);
|
|
|
|
public void PerformClick() => this.OnClick(null);
|
|
}
|
|
} |