2020-05-15 22:34:31 +00:00
|
|
|
|
using System.Drawing;
|
2020-05-10 10:03:55 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace RyzStudio.Windows.Forms
|
|
|
|
|
{
|
2020-05-15 00:19:09 +00:00
|
|
|
|
public class TFlatButton : Label
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
2020-05-15 22:34:31 +00:00
|
|
|
|
public class ButtonStyle
|
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
|
|
|
|
|
2020-05-15 00:19:09 +00:00
|
|
|
|
public TFlatButton() : base()
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
this.AutoSize = false;
|
|
|
|
|
this.ImageAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
this.TextAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
|
|
|
|
|
// customise
|
2020-05-15 22:34:31 +00:00
|
|
|
|
this.StyleOver = new ButtonStyle()
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
BackColour = Color.FromArgb(51, 51, 51),
|
|
|
|
|
PenColour = Color.White
|
|
|
|
|
};
|
2020-05-15 22:34:31 +00:00
|
|
|
|
this.StyleDown = new ButtonStyle()
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
BackColour = Color.FromArgb(179, 179, 179),
|
|
|
|
|
PenColour = Color.Black
|
|
|
|
|
};
|
2020-05-15 22:34:31 +00:00
|
|
|
|
this.StyleDefault = new ButtonStyle()
|
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-15 22:34:31 +00:00
|
|
|
|
protected void updateButton(ButtonStyle style)
|
2020-05-10 10:03:55 +00:00
|
|
|
|
{
|
|
|
|
|
this.ForeColor = style.PenColour;
|
|
|
|
|
this.BackColor = style.BackColour;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 22:34:31 +00:00
|
|
|
|
protected ButtonStyle StyleOver { get; set; } = new ButtonStyle();
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
2020-05-15 22:34:31 +00:00
|
|
|
|
protected ButtonStyle StyleDown { get; set; } = new ButtonStyle();
|
2020-05-10 10:03:55 +00:00
|
|
|
|
|
2020-05-15 22:34:31 +00:00
|
|
|
|
protected ButtonStyle StyleDefault { get; set; } = new ButtonStyle();
|
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
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|