You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
4.0 KiB
C#
119 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rs.Controls
|
|
{
|
|
public enum EButtonType
|
|
{
|
|
None,
|
|
Main,
|
|
Data,
|
|
Recipe,
|
|
System,
|
|
About,
|
|
Permission,
|
|
Language,
|
|
Quit
|
|
}
|
|
public class ButtonEx : Button
|
|
{
|
|
|
|
public EButtonType ButtonType { get; set; } = EButtonType.None;
|
|
private bool selected = false;
|
|
|
|
/// <summary>
|
|
/// 被选中
|
|
/// </summary>
|
|
public bool Selected
|
|
{
|
|
get { return selected; }
|
|
set
|
|
{
|
|
selected = value;
|
|
if (selected)
|
|
{
|
|
this.BackColor = SelectedColor;
|
|
//this.FlatAppearance.BorderColor = Color.Red;
|
|
}
|
|
else
|
|
{
|
|
//this.FlatAppearance.BorderColor = Color.White;
|
|
this.BackColor = UnSelectedColor;
|
|
}
|
|
Invalidate();
|
|
}
|
|
}
|
|
|
|
public Color SelectedColor { get; set; } = Color.FromArgb(57, 136, 203);
|
|
public Color UnSelectedColor { get; set; } = Color.FromArgb(19, 52, 104);
|
|
|
|
public string ShowText { get; set; }
|
|
public string ShowIcon { get; set; }
|
|
protected override void OnPaint(PaintEventArgs pevent)
|
|
{
|
|
string text = this.Text;
|
|
this.Text = "";
|
|
base.OnPaint(pevent);
|
|
FontFamily ff = IconFontHelper.PFCC.Families[0];
|
|
SizeF textSize = pevent.Graphics.MeasureString(this.Text, this.Font);
|
|
string str = "";
|
|
Font font = new Font(ff, 30);
|
|
switch (ButtonType)
|
|
{
|
|
case EButtonType.None:
|
|
break;
|
|
case EButtonType.Main:
|
|
str = " \ue648";
|
|
break;
|
|
case EButtonType.Data:
|
|
str = " \ue93a";
|
|
break;
|
|
case EButtonType.Recipe:
|
|
str = " \ue682";
|
|
break;
|
|
case EButtonType.System:
|
|
str = " \ue630";
|
|
break;
|
|
case EButtonType.About:
|
|
str = " \ue603";
|
|
break;
|
|
case EButtonType.Permission:
|
|
str = " \ue66d";
|
|
break;
|
|
case EButtonType.Language:
|
|
str = " \ue654";
|
|
break;
|
|
case EButtonType.Quit:
|
|
str = " \ue67d";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
SizeF size = pevent.Graphics.MeasureString(str, font);
|
|
StringFormat sf = new StringFormat();
|
|
sf.Alignment = StringAlignment.Center;
|
|
sf.LineAlignment = StringAlignment.Center;
|
|
RectangleF rect = new RectangleF(0, 0, ClientRectangle.Width, ClientRectangle.Height);
|
|
pevent.Graphics.DrawString(ShowText, this.Font, new SolidBrush(this.ForeColor), rect, sf);
|
|
sf.Alignment = StringAlignment.Near;
|
|
pevent.Graphics.DrawString(str, font, new SolidBrush(ForeColor), rect, sf);
|
|
|
|
//if(selected)
|
|
//{
|
|
// LinearGradientBrush br = new LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 0, false);
|
|
// ColorBlend cb = new ColorBlend();
|
|
// cb.Positions = new[] { 0, 0.5f, 1.0f };
|
|
// cb.Colors = new[] { Color.FromArgb(18, 53, 106), Color.FromArgb(67, 158, 229), Color.FromArgb(18, 53, 106) };
|
|
// br.InterpolationColors = cb;
|
|
// br.RotateTransform(180);
|
|
// pevent.Graphics.FillRectangle(br, this.ClientRectangle);
|
|
// }
|
|
}
|
|
}
|
|
}
|