This repository has been archived on 2022-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
bookmark-manager/RyzStudio/Windows/ThemedForms/Button.cs

106 lines
2.6 KiB
C#
Raw Permalink Normal View History

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)]
2019-04-23 20:57:35 +00:00
public ButtonStyle StyleOver { get; set; } = new ButtonStyle(Color.FromArgb(71, 142, 203), Color.FromArgb(250, 250, 250));
2019-04-23 20:57:35 +00:00
[Browsable(false)]
public ButtonStyle StyleDown { get; set; } = new ButtonStyle(Color.FromArgb(61, 132, 193), Color.FromArgb(250, 250, 250));
2019-04-23 20:57:35 +00:00
[Browsable(false)]
public ButtonStyle StyleDefault { get; set; } = new ButtonStyle(Color.FromArgb(51, 122, 183), Color.FromArgb(250, 250, 250));
2019-04-21 17:53:56 +00:00
public void PerformClick() => this.OnClick(null);
}
}