2020-05-10 10:03:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace RyzStudio.Windows.Forms
|
|
|
|
|
{
|
|
|
|
|
public class FlatButton : Label
|
|
|
|
|
{
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public class FlatButtonStyle
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
public Color BackColour { get; set; } = Color.Transparent;
|
|
|
|
|
public Color PenColour { get; set; } = Color.Transparent;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public enum FlatButtonState
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
Idle = 0,
|
|
|
|
|
Hover,
|
|
|
|
|
Down
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
protected FlatButtonState controlState = FlatButtonState.Idle;
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
|
|
|
|
public FlatButton() : base()
|
|
|
|
|
{
|
|
|
|
|
this.AutoSize = false;
|
|
|
|
|
this.ImageAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
this.TextAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
|
|
|
|
|
// customise
|
2020-05-12 23:37:01 +00:00
|
|
|
|
this.StyleOver = new FlatButtonStyle()
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
BackColour = Color.FromArgb(51, 51, 51),
|
|
|
|
|
PenColour = Color.White
|
|
|
|
|
};
|
2020-05-12 23:37:01 +00:00
|
|
|
|
this.StyleDown = new FlatButtonStyle()
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
BackColour = Color.FromArgb(179, 179, 179),
|
|
|
|
|
PenColour = Color.Black
|
|
|
|
|
};
|
2020-05-12 23:37:01 +00:00
|
|
|
|
this.StyleDefault = new FlatButtonStyle()
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
BackColour = Color.White,
|
|
|
|
|
PenColour = Color.Black
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
this.VisualState = FlatButtonState.Idle;
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
|
|
|
|
this.Click += delegate { this.OnClick(null); };
|
2020-05-12 23:37:01 +00:00
|
|
|
|
this.MouseEnter += delegate { this.VisualState = FlatButtonState.Hover; };
|
|
|
|
|
this.MouseLeave += delegate { this.VisualState = FlatButtonState.Idle; };
|
|
|
|
|
this.MouseDown += delegate { this.VisualState = FlatButtonState.Down; };
|
|
|
|
|
this.MouseUp += delegate { this.VisualState = FlatButtonState.Idle; };
|
2020-05-10 10:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
protected FlatButtonState VisualState
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
get { return controlState; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
switch (value)
|
|
|
|
|
{
|
2020-05-12 23:37:01 +00:00
|
|
|
|
case FlatButtonState.Idle:
|
|
|
|
|
if (this.VisualState == FlatButtonState.Down)
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
updateButton(StyleOver);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
updateButton(StyleDefault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2020-05-12 23:37:01 +00:00
|
|
|
|
case FlatButtonState.Hover:
|
2020-05-10 10:03:55 +00:00
|
|
|
|
updateButton(StyleOver);
|
|
|
|
|
break;
|
2020-05-12 23:37:01 +00:00
|
|
|
|
case FlatButtonState.Down:
|
2020-05-10 10:03:55 +00:00
|
|
|
|
updateButton(StyleDown);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
updateButton(StyleDefault);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controlState = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
protected void updateButton(FlatButtonStyle style)
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
this.ForeColor = style.PenColour;
|
|
|
|
|
this.BackColor = style.BackColour;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public FlatButtonStyle StyleOver { get; set; } = new FlatButtonStyle();
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public FlatButtonStyle StyleDown { get; set; } = new FlatButtonStyle();
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public FlatButtonStyle StyleDefault { get; set; } = new FlatButtonStyle();
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
2020-05-10 10:34:45 +00:00
|
|
|
|
public void PerformClick()
|
|
|
|
|
{
|
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke(new MethodInvoker(() => {
|
|
|
|
|
this.OnClick(null);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.OnClick(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|