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.

74 lines
2.4 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 EButtonMode
{
MIN,
MAX,
CLOSE,
NOMAL
}
public class IconButton:Button
{
public EButtonMode ButtonType { get; set; } = EButtonMode.MIN;
protected override void OnPaint(PaintEventArgs pevent)
{
this.Text = "";
base.OnPaint(pevent);
FontFamily ff = IconFontHelper.PFCC.Families[0];
SizeF textSize = pevent.Graphics.MeasureString(this.Text, this.Font);
Font font = new Font(ff, 15);
//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);
switch (ButtonType)
{
case EButtonMode.MIN:
pevent.Graphics.DrawString("\ue624", font, new SolidBrush(ForeColor), rect, sf);
break;
case EButtonMode.MAX:
pevent.Graphics.DrawString("\ue65d", font, new SolidBrush(ForeColor), rect, sf);
break;
case EButtonMode.CLOSE:
pevent.Graphics.DrawString("\ueca0", font, new SolidBrush(ForeColor), rect, sf);
break;
case EButtonMode.NOMAL:
pevent.Graphics.DrawString("\uea6b", font, new SolidBrush(ForeColor), rect, sf);
break;
default:
break;
}
}
public static byte[] hexStringToByte(String hex)
{
int len = (hex.Length / 2);
byte[] result = new byte[len];
char[] achar = hex.ToCharArray();
for (int i = 0; i < len; i++)
{
int pos = i * 2;
result[i] = (byte)(toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
}
return result;
}
private static int toByte(char c)
{
byte b = (byte)"0123456789ABCDEF".IndexOf(c);
return b;
}
}
}