📄 qbutton.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace Qeb.Control
{
public partial class QButton : System.Windows.Forms.Button
{
#region About Constructor
public QButton()
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.UserPaint |
ControlStyles.ResizeRedraw |
ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.Opaque, false);
this.FlatAppearance.BorderSize = 0;
this.FlatStyle = FlatStyle.Flat;
this.BackColor = Color.Transparent;
timer1.Interval = 5;
timer1.Tick += new EventHandler(timer1_Tick);
}
protected override void OnCreateControl()
{
base.OnCreateControl();
A0 = ColorBase.A;
R0 = ColorBase.R;
G0 = ColorBase.G;
B0 = ColorBase.B;
_colorStroke = _baseStroke;
Rectangle r = new Rectangle(new Point(-1, -1), new Size(this.Width + _radius, this.Height + _radius));
#region Transform to SmoothRectangle Region
if (this.Size != null)
{
GraphicsPath pathregion = new GraphicsPath();
DrawArc(r, pathregion);
this.Region = new Region(pathregion);
}
#endregion
}
#endregion
#region About Image Settings
private imagelocation _imagelocation;
public enum imagelocation
{
Top,Bottom,Left,Right,None
}
public imagelocation ImageLocation
{
get { return _imagelocation; }
set { _imagelocation = value; this.Refresh(); }
}
private int _imageoffset;
public int ImageOffset
{
get { return _imageoffset; }
set { _imageoffset = value; }
}
private Point maximagesize;
public Point MaxImageSize
{
get { return maximagesize; }
set { maximagesize = value; }
}
#endregion
#region About Button Settings
private showbase _oldshowbase;
private showbase _showbase;
private showbase _tempshowbase;
public enum showbase
{
Yes,No
}
public showbase ShowBase
{
get { return _showbase; }
set { _oldshowbase=value; _showbase = value; this.Refresh(); }
}
private int _radius = 6;
public int Radius
{
get { return _radius; }
set { if (_radius > 0) _radius = value; this.Refresh(); }
}
private groupPos _grouppos;
public enum groupPos
{
None,Left,Center,Right,Top,Bottom
}
public groupPos GroupPos
{
get { return _grouppos; }
set { _grouppos = value; this.Refresh(); }
}
private arrow _arrow;
public enum arrow
{
None, ToRight, ToDown
}
public arrow Arrow
{
get { return _arrow; }
set { _arrow = value; this.Refresh(); }
}
private splitbutton _splitbutton;
public enum splitbutton
{
No, Yes
}
public splitbutton SplitButton
{
get { return _splitbutton; }
set { _splitbutton = value; this.Refresh(); }
}
private int _splitdistance = 0;
public int SplitDistance
{
get { return _splitdistance; }
set { _splitdistance = value; this.Refresh(); }
}
private string _title = "";
public string Title
{
get { return _title; }
set { _title = value; this.Refresh(); }
}
#endregion
#region Colors
//private Color _baseColor = Color.FromArgb(209, 209, 209);
//private Color _onColor = Color.FromArgb(255, 255, 255);
//private Color _pressColor = Color.FromArgb(255, 255, 255);
//private Color _baseStroke = Color.FromArgb(255, 255, 255);
//private Color _onStroke = Color.FromArgb(255, 255, 255);
//private Color _pressStroke = Color.FromArgb(255, 255, 255);
//private Color _colorStroke = Color.FromArgb(255, 255, 255);
private Color _baseColor = Color.FromArgb(186, 209, 240);
private Color _onColor = Color.FromArgb(255, 214, 78);
private Color _pressColor = Color.FromArgb(255, 128, 0);
private Color _baseStroke = Color.FromArgb(152, 187, 213);
private Color _onStroke = Color.FromArgb(196, 177, 118);
private Color _pressStroke = Color.FromArgb(128, 64, 0);
private Color _colorStroke = Color.FromArgb(255, 255, 255);
private int A0,R0, G0, B0;
public Color ColorBase
{
get { return _baseColor; }
set
{
_baseColor = value;
R0 = _baseColor.R;
B0 = _baseColor.B;
G0 = _baseColor.G;
A0 = _baseColor.A;
RibbonColor hsb = new RibbonColor(_baseColor);
if (hsb.BC<50)
{
hsb.SetBrightness(60);
}
else
{
hsb.SetBrightness(30);
}
if(_baseStroke.A >0)
_baseStroke = Color.FromArgb(100,hsb.GetColor());
else
_baseStroke = Color.FromArgb(0, hsb.GetColor());
}
}
public Color ColorOn
{
get { return _onColor; }
set { _onColor = value;
RibbonColor hsb = new RibbonColor(_onColor);
if (hsb.BC < 50)
{
hsb.SetBrightness(60);
}
else
{
hsb.SetBrightness(30);
}
if (_baseStroke.A > 0)
_onStroke = Color.FromArgb(100, hsb.GetColor());
else
_onStroke = Color.FromArgb(0, hsb.GetColor());
}
}
public Color ColorPress
{
get { return _pressColor; }
set { _pressColor = value;
RibbonColor hsb = new RibbonColor(_pressColor);
if (hsb.BC < 50)
{
hsb.SetBrightness(60);
}
else
{
hsb.SetBrightness(30);
}
if (_baseStroke.A > 0)
_pressStroke = Color.FromArgb(100, hsb.GetColor());
else
_pressStroke = Color.FromArgb(0, hsb.GetColor());
}
}
public Color ColorBaseStroke
{
get { return _baseStroke; }
set { _baseStroke = value; }
}
public Color ColorOnStroke
{
get { return _onStroke; }
set { _onStroke = value; }
}
public Color ColorPressStroke
{
get { return _pressStroke; }
set { _pressStroke = value; }
}
public Color GetColorIncreased(Color color,int h,int s,int b)
{
RibbonColor _color = new RibbonColor(color);
int ss = _color.GetSaturation();
float vc = b + _color.GetBrightness();
float hc = h+ _color.GetHue();
float sc = s + ss;
_color.VC = vc;
_color.HC = hc;
_color.SC = sc;
return _color.GetColor();
}
public Color GetColor(int A,int R, int G, int B)
{
if (A + A0 > 255) { A = 255; } else { A = A + A0; }
if (R + R0 > 255) { R = 255; } else { R = R + R0; }
if (G + G0 > 255) { G = 255; } else { G = G + G0; }
if (B + B0 > 255) { B = 255; } else { B = B + B0; }
return Color.FromArgb(A,R, G, B);
}
#endregion
protected override void OnPaint(PaintEventArgs pevent)
{
#region Variables & Conf
Graphics g = pevent.Graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.High;
Rectangle r = new Rectangle(new Point(-1,-1), new Size(this.Width+_radius, this.Height+_radius));
#endregion
#region Paint
GraphicsPath path = new GraphicsPath();
Rectangle rp = new Rectangle(new Point(0, 0), new Size(this.Width-1, this.Height-1)); DrawArc(rp,path);
FillGradients(g,path);
DrawImage(g);
DrawString(g);
DrawArrow(g);
#endregion
}
#region Paint Methods
public void FillGradients(Graphics gr,GraphicsPath pa)
{
int origin = this.Height/3; int end = this.Height; int oe = (end - origin) / 2;
LinearGradientBrush lgbrush; Rectangle rect;
if (_showbase == showbase.Yes)
{
rect = new Rectangle(new Point(0, 0), new Size(this.Width - 1, this.Height - 1));
pa = new GraphicsPath();
DrawArc(rect, pa);
lgbrush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical);
#region Main Gradient
float[] pos = new float[4];
pos[0] = 0.0F; pos[1] = 0.3F; pos[2] = 0.35F; pos[3] = 1.0F;
Color[] colors = new Color[4];
if (i_mode == 0)
{
colors[0] = GetColor(0, 35, 24, 9);
colors[1] = GetColor(0, 13, 8, 3);
colors[2] = Color.FromArgb(A0, R0, G0, B0);
colors[3] = GetColor(0, 28, 29, 14);
}
else
{
colors[0] = GetColor(0, 0, 50, 100);
colors[1] = GetColor(0, 0, 0, 30);
colors[2] = Color.FromArgb(A0, R0, G0, B0);
colors[3] = GetColor(0, 0, 50, 100);
}
ColorBlend mix = new ColorBlend();
mix.Colors = colors;
mix.Positions = pos;
lgbrush.InterpolationColors = mix;
gr.FillPath(lgbrush, pa);
#endregion
#region Fill Band
rect = new Rectangle(new Point(0, 0), new Size(this.Width, this.Height/3));
pa = new GraphicsPath(); int _rtemp = _radius; _radius = _rtemp - 1;
DrawArc(rect, pa);
if (A0 > 80)
{
gr.FillPath(new SolidBrush(Color.FromArgb(60, 255, 255, 255)), pa);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -