using Microsoft.VisualBasic.CompilerServices; using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace BaseLibRWFile { public partial class ControlBeautify : Component { } public partial class TXbutton : Button { public bool status = false; private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color) { try { int span = 2; //抗锯齿 g.SmoothingMode = SmoothingMode.AntiAlias; //渐变填充 LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical); //画尖角 if (cusp) { span = 10; PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10); PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30); PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20); PointF[] ptsArray = { p1, p2, p3 }; g.FillPolygon(myLinearGradientBrush, ptsArray); } //填充 g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius)); } catch { } } public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius) { //四边圆角 GraphicsPath gp = new GraphicsPath(); gp.AddArc(x, y, radius, radius, 180, 90); gp.AddArc(width - radius, y, radius, radius, 270, 90); gp.AddArc(width - radius, height - radius, radius, radius, 0, 90); gp.AddArc(x, height - radius, radius, radius, 90, 90); gp.CloseAllFigures(); return gp; } public string name = null; //名称 public string name_move = null; public int font_size = 9; //字体的大小 public Color TXcolor_start; //渐变色的颜色,start开始,end结束 public Color TXcolor_end; public Color TXcolor_start_move; public Color TXcolor_end_move; public Image TX_image = null; protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); base.OnPaintBackground(e); StringFormat strFormat = new StringFormat(); strFormat.Alignment=StringAlignment.Center; strFormat.LineAlignment = StringAlignment.Center; Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); //System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); //path.AddEllipse(0, 0, this.Width, this.Height); //this.Region = new Region(path); //this.FlatStyle = FlatStyle.Flat; //this.FlatAppearance.BorderSize = 0; //this.Text = null; //font_size = 10; this.FlatAppearance.MouseOverBackColor = Color.Transparent; this.FlatAppearance.MouseDownBackColor = Color.Transparent; if (status == false) { if (TXcolor_start.IsEmpty) { Draw(e.ClipRectangle, e.Graphics, 25, false, Color.FromArgb(0xEA, 0xEA, 0xEB), Color.FromArgb(0xEA, 0xEA, 0xEB)); } else { Draw(e.ClipRectangle, e.Graphics, 25, false, TXcolor_start, TXcolor_start); } if (name != null) { //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight)); e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect,strFormat); } if (TX_image != null) { e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height); } this.Cursor = Cursors.Arrow; } else { if (TXcolor_start_move.IsEmpty) { Draw(e.ClipRectangle, e.Graphics, 25, false, Color.FromArgb(0xAE, 0xDA, 0x97), Color.FromArgb(0xAE, 0xDA, 0x97)); } else { Draw(e.ClipRectangle, e.Graphics, 25, false, TXcolor_start_move, TXcolor_start_move); } if (name != null) { //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight)); e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect, strFormat); } if (TX_image != null) { e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height); } this.Cursor = Cursors.Arrow; } } //protected override void OnPaintBackground(PaintEventArgs e) //{ // base.OnPaintBackground(e); // Draw(e.ClipRectangle, e.Graphics, 12, false, Color.Gray, Color.Green); //} //protected override void OnMouseEnter(EventArgs e) //{ // base.OnMouseEnter(e); // status = true; // //Draw(e.ClipRectangle, e.Graphics, 25, false, Color.Gray, Color.Green); //} //protected override void OnMouseLeave(EventArgs e) //{ // base.OnMouseLeave(e); // status = false; // //Draw(e.ClipRectangle, e.Graphics, 12, false, Color.Gray, Color.Green); //} //protected override void OnMouseDown(MouseEventArgs mevent) //{ // base.OnMouseDown(mevent); // status = true; //} } public partial class TXlabel : Label { public bool status = false; private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color) { try { int span = 2; //抗锯齿 g.SmoothingMode = SmoothingMode.AntiAlias; //渐变填充 LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical); //画尖角 if (cusp) { span = 10; PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10); PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30); PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20); PointF[] ptsArray = { p1, p2, p3 }; g.FillPolygon(myLinearGradientBrush, ptsArray); } //填充 g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius)); } catch { } } public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius) { //四边圆角 GraphicsPath gp = new GraphicsPath(); gp.AddArc(x, y, radius, radius, 180, 90); gp.AddArc(width - radius, y, radius, radius, 270, 90); gp.AddArc(width - radius, height - radius, radius, radius, 0, 90); gp.AddArc(x, height - radius, radius, radius, 90, 90); gp.CloseAllFigures(); return gp; } public string name = null; //名称 public string name_move = null; public int font_size = 12; //字体的大小 public Color TXcolor_start; //渐变色的颜色,start开始,end结束 public Color TXcolor_end; public Color TXcolor_start_move; public Color TXcolor_end_move; public Image TX_image = null; protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); base.OnPaintBackground(e); StringFormat strFormat = new StringFormat(); strFormat.Alignment = StringAlignment.Center; strFormat.LineAlignment = StringAlignment.Center; Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); name = this.Text; font_size = Convert.ToInt32(this.Font.Size); if (status == false) { if (TXcolor_start.IsEmpty) { Draw(e.ClipRectangle, e.Graphics, 12, false, Color.FromArgb(0xAE, 0xDA, 0x97), Color.FromArgb(0xAE, 0xDA, 0x97)); } else { Draw(e.ClipRectangle, e.Graphics, 12, false, TXcolor_start, TXcolor_start); } if (name != null) { //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight)); e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect, strFormat); } if (TX_image != null) { e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height); } this.Cursor = Cursors.Arrow; } else { if (TXcolor_start_move.IsEmpty) { Draw(e.ClipRectangle, e.Graphics, 12, false, Color.FromArgb(0xAE, 0xDA, 0x97), Color.FromArgb(0xAE, 0xDA, 0x97)); } else { Draw(e.ClipRectangle, e.Graphics, 12, false, TXcolor_start_move, TXcolor_start_move); } if (name != null) { //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight)); e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect, strFormat); } if (TX_image != null) { e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height); } this.Cursor = Cursors.Arrow; } } //protected override void OnPaintBackground(PaintEventArgs e) //{ // //base.OnPaintBackground(e); // //Draw(e.ClipRectangle, e.Graphics, 18, false, Color.Gray, Color.Green); //} //protected override void OnMouseEnter(EventArgs e) //{ // base.OnMouseEnter(e); // //if (!this.Enabled) // //{ // // return; // //} // //this.m_OldBkColor = this.BackColor; // //this.IsOnEnter = true; // //this.IsOnLeave = false; // //this.Invalidate(); //} //protected override void OnMouseLeave(EventArgs e) //{ // base.OnMouseLeave(e); //} //protected override void OnMouseDown(MouseEventArgs mevent) //{ // base.OnMouseDown(mevent); // status = true; //} } public partial class TXpanel : Panel { bool status = false; private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color) { try { int span = 2; //抗锯齿 g.SmoothingMode = SmoothingMode.AntiAlias; //渐变填充 LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical); //画尖角 if (cusp) { span = 10; PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10); PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30); PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20); PointF[] ptsArray = { p1, p2, p3 }; g.FillPolygon(myLinearGradientBrush, ptsArray); } //填充 g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius)); } catch { } } public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius) { //四边圆角 GraphicsPath gp = new GraphicsPath(); gp.AddArc(x, y, radius, radius, 180, 90); gp.AddArc(width - radius, y, radius, radius, 270, 90); gp.AddArc(width - radius, height - radius, radius, radius, 0, 90); gp.AddArc(x, height - radius, radius, radius, 90, 90); gp.CloseAllFigures(); return gp; } public string name = null; //名称 public string name_move = null; public int font_size = 12; //字体的大小 public Color TXcolor_start; //渐变色的颜色,start开始,end结束 public Color TXcolor_end; public Color TXcolor_start_move; public Color TXcolor_end_move; public Image TX_image = null; protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (status == false) { if (TXcolor_start.IsEmpty) { //Draw(e.ClipRectangle, e.Graphics, 12, false, Color.FromArgb(0xEA, 0xEA, 0xEB), Color.FromArgb(0xEA, 0xEA, 0xEB)); Draw(e.ClipRectangle, e.Graphics, 20, false, SystemColors.Control, SystemColors.Control); } else { Draw(e.ClipRectangle, e.Graphics, 20, false, TXcolor_start, TXcolor_start); } e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(font_size + font_size / 2, this.Height / 2 - FontHeight)); if (TX_image != null) { e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height); } this.Cursor = Cursors.Arrow; } else { if (TXcolor_start_move.IsEmpty) { Draw(e.ClipRectangle, e.Graphics, 20, false, SystemColors.Control, SystemColors.Control); } else { Draw(e.ClipRectangle, e.Graphics, 20, false, TXcolor_start_move, TXcolor_start_move); } e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(font_size + font_size / 2, this.Height / 2 - FontHeight)); if (TX_image != null) { e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height); } this.Cursor = Cursors.Arrow; } } //protected override void OnPaintBackground(PaintEventArgs e) //{ // //base.OnPaintBackground(e); // //Draw(e.ClipRectangle, e.Graphics, 18, false, Color.Gray, Color.Green); //} //protected override void OnMouseEnter(EventArgs e) //{ // base.OnMouseEnter(e); // status = true; //} //protected override void OnMouseLeave(EventArgs e) //{ // base.OnMouseLeave(e); // status = false; //} //protected override void OnMouseDown(MouseEventArgs mevent) //{ // base.OnMouseDown(mevent); //} } public partial class TXbutton_circular : Button { protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; GraphicsPath path = new GraphicsPath(); path.AddEllipse(0, 0, this.Width, this.Height); this.FlatAppearance.BorderSize = 0; this.Region = new Region(path); } } public class TXDraw : Panel { Color Draw_Color = Color.FromArgb(30, 255, 50); public int Percentage = 0; public int Percentage_current = 0; protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // path.AddEllipse(0, 0, this.Width, this.Height); Rectangle ret = new Rectangle(0, 0, this.Width, this.Height); path.AddRectangle(ret); this.Region = new Region(path); Graphics ex = this.CreateGraphics(); Rectangle retc = new Rectangle(10, 10, 180, 180); Rectangle retd = new Rectangle(35, 35, 130, 130); Rectangle rete = new Rectangle(40, 40, 120, 120); Rectangle retf = new Rectangle(65, 65, 70, 70); Rectangle retg = new Rectangle(70, 70, 60, 60); System.Drawing.Font strname_ok_ng = new System.Drawing.Font("黑体", 15, FontStyle.Bold); System.Drawing.Font strname = new System.Drawing.Font("黑体", 10, FontStyle.Bold); StringFormat ss = new StringFormat(StringFormatFlags.DirectionVertical); ex.DrawArc(new Pen(Draw_Color), retc, 180, 180); ex.DrawArc(new Pen(Draw_Color), retd, 180, 180); ex.FillPie(new SolidBrush(Draw_Color), retc, 180, 180); ex.FillPie(new SolidBrush(Color.Red), retc, 180, Percentage); //百分比100% ex.FillPie(Brushes.White, retd, 180, 180); ex.DrawArc(new Pen(Draw_Color), rete, 180, 180); ex.DrawArc(new Pen(Draw_Color), retf, 180, 180); ex.FillPie(new SolidBrush(Draw_Color), rete, 180, 180); ex.FillPie(new SolidBrush(Color.Red), rete, 180, Percentage_current); //百分比100% ex.FillPie(Brushes.White, retf, 180, 180); ex.DrawArc(new Pen(Color.Red), retg, 180, 180); ex.FillPie(Brushes.Red, retg, 360, 360); ex.DrawString("OK", strname_ok_ng, Brushes.White, 90, 90, StringFormat.GenericTypographic); ex.DrawString(System.DateTime.Now.ToString("d"), strname_ok_ng, Brushes.Black, 20, 140, StringFormat.GenericTypographic); } } public class TXDrawA : Panel { public int Percentage = 0; public int Percentage_current = 0; protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); //path.AddEllipse(0, 0, this.Width, this.Height); Rectangle ret = new Rectangle(0, 0, this.Width, this.Height); path.AddRectangle(ret); this.Region = new Region(path); int WidthX = e.ClipRectangle.Width; int HeightY = e.ClipRectangle.Height; Graphics ex = this.CreateGraphics(); ex.SmoothingMode = SmoothingMode.AntiAlias; System.Drawing.Font strname_ok_ng = new System.Drawing.Font("黑体", 15, FontStyle.Bold); System.Drawing.Font strname = new System.Drawing.Font("黑体", 10, FontStyle.Bold); StringFormat ss = new StringFormat(StringFormatFlags.DirectionVertical); Pen myPen = new Pen(this.ForeColor, 30); ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 170, 48); ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 220, 53); ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 275, 48); ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 325, 48); string[] name = AccessibleName.Split(','); int X1 = int.Parse(name[0]); int X2 = int.Parse(name[1]); double k = 0, b = 0; Calculate(X1, X2, -100, 100, ref k, ref b); double A = (k * int.Parse(this.Tag.ToString()) + b); int Value; if (A >= 0) { Value = (int)A; } else { A = -A; Value = (int)A; Value = -Value; } //表中心点 Point centerPoint = new Point(Convert.ToInt32(WidthX * 0.7) - Convert.ToInt32(WidthX * 0.4) / 2, Convert.ToInt32(HeightY * 0.8) - Convert.ToInt32(HeightY * 0.4) / 2); Point secPoint = new Point((int)(centerPoint.X + (Math.Sin(Value * Math.PI / 180)) * (Convert.ToInt32(HeightY * 0.99) - Convert.ToInt32(HeightY * 0.01)) / 2), (int)(centerPoint.Y - (Math.Cos(Value * Math.PI / 180)) * (Convert.ToInt32(HeightY * 0.99) - Convert.ToInt32(HeightY * 0.01)) / 2)); myPen = new Pen(Color.FromArgb(239, 144, 0), 5); ex.DrawLine(myPen, centerPoint, secPoint); e.Graphics.DrawString(this.Tag.ToString(), this.Font, new SolidBrush(Color.Black), Convert.ToInt32((Convert.ToInt32(WidthX * 0.7) - Convert.ToInt32(WidthX * 0.2)) - (double)ex.MeasureString(this.Tag.ToString(), this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.8) - Convert.ToInt32(HeightY * 0.35) / 2); e.Graphics.DrawString(name[0], this.Font, new SolidBrush(Color.Black), Convert.ToInt32(WidthX * 0.15 - (double)ex.MeasureString(name[0], this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.7)); e.Graphics.DrawString(name[1], this.Font, new SolidBrush(Color.Black), Convert.ToInt32(WidthX * 0.85 - (double)ex.MeasureString(name[1], this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.7)); e.Graphics.DrawString(name[3], this.Font, new SolidBrush(Color.Black), Convert.ToInt32(WidthX * 0.5 - (double)ex.MeasureString(name[3], this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.85)); } private const int _decimaldigits = 2;//小数位数保留2位 private static void Calculate(float x1, float x2, float y1, float y2, ref double kvalue, ref double bvalue)//求方程y=kx+b 系数 k ,b { float coefficient = 1;//系数值 try { if ((x1 == 0) || (x2 == 0) || (x1 == x2)) { if (x1 == 0) { x1 = 1; } if (x2 == 0) { x2 = 1; } } //; //排除为零的情况以及x1,x2相等时无法运算的情况 //if (y1 == y2) return; //根据具体情况而定,如何这两个值相等,得到的就是一条直线 float temp = 0; if (x1 >= x2) { coefficient = (float)Math.Round((x1 / x2), _decimaldigits); temp = y2 * coefficient; //将对应的函数乘以系数 bvalue = (double)Math.Round(((temp - y1) / (coefficient - 1)), _decimaldigits); kvalue = (double)Math.Round(((y1 - bvalue) / x1), _decimaldigits); //求出k值 } else { coefficient = x2 / x1; temp = y1 * coefficient; bvalue = (double)Math.Round(((temp - y2) / (coefficient - 1)), _decimaldigits);//求出b值 kvalue = (double)Math.Round(((y2 - bvalue) / x2), _decimaldigits); //求出k值 } } catch { Console.WriteLine("x系数不能为0或相等"); } } } [OptionText] public class RoundPanel : Panel { private int m_iRoundRadius; private bool m_bAutoBkColor; public byte Radius { get { return checked((byte)this.m_iRoundRadius); } set { this.m_iRoundRadius = (int)value; this.Invalidate(); } } public bool AutoBkColor { get { return this.m_bAutoBkColor; } set { this.m_bAutoBkColor = value; this.Invalidate(); } } public RoundPanel() { this.m_iRoundRadius = 15; this.m_bAutoBkColor = false; this.ForeColor = Color.Gray; this.Width = 120; this.Height = 50; this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.ResizeRedraw, true); } private void Check() { checked { if ((double)this.m_iRoundRadius > (double)this.Width / 2.0 | (double)this.m_iRoundRadius > (double)this.Height / 2.0) { if ((double)this.Width / 2.0 > (double)this.Height / 2.0) { this.m_iRoundRadius = (int)Math.Round((double)this.Height / 2.0); } else { this.m_iRoundRadius = (int)Math.Round((double)this.Width / 2.0); } } else if (this.m_iRoundRadius < 0) { this.m_iRoundRadius = 0; } if (this.Parent.GetType() == typeof(RoundPanel)) { if (this.m_bAutoBkColor) { this.BackColor = this.Parent.ForeColor; } } else if (this.m_bAutoBkColor) { this.BackColor = this.Parent.BackColor; } } } protected override void OnParentBackColorChanged(EventArgs e) { if (!(this.Parent.GetType() == typeof(RoundPanel)) && this.m_bAutoBkColor) { this.BackColor = this.Parent.BackColor; } } protected override void OnParentForeColorChanged(EventArgs e) { if (this.Parent.GetType() == typeof(RoundPanel) && this.m_bAutoBkColor) { this.BackColor = this.Parent.ForeColor; } } protected override void OnPaint(PaintEventArgs e) { checked { try { this.Check(); Graphics graphics = e.Graphics; Rectangle rect = new Rectangle(e.ClipRectangle.Left + this.m_iRoundRadius, e.ClipRectangle.Top, e.ClipRectangle.Right - 2 * this.m_iRoundRadius, e.ClipRectangle.Bottom); Rectangle rect2 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top + this.m_iRoundRadius, e.ClipRectangle.Right, e.ClipRectangle.Bottom - 2 * this.m_iRoundRadius); Rectangle rect3 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius); Rectangle rect4 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_iRoundRadius, e.ClipRectangle.Top, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius); Rectangle rect5 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Bottom - 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius - 1); Rectangle rect6 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_iRoundRadius, e.ClipRectangle.Bottom - 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius - 1); graphics.Clear(this.BackColor); graphics.SmoothingMode = SmoothingMode.AntiAlias; Brush brush = new SolidBrush(this.ForeColor); graphics.FillRectangle(brush, rect); graphics.FillRectangle(brush, rect2); if (this.m_iRoundRadius != 0) { graphics.FillPie(brush, rect3, 170f, 120f); graphics.FillPie(brush, rect4, 260f, 120f); graphics.FillPie(brush, rect5, 80f, 120f); graphics.FillPie(brush, rect6, 350f, 120f); } brush.Dispose(); } catch (Exception arg_23F_0) { ProjectData.SetProjectError(arg_23F_0); ProjectData.ClearProjectError(); } } } } [OptionText] public class RoundButton : Button { private int m_RoundRadius; private Color m_OldBkColor; private bool IsClicked; private bool IsOnEnter; private bool IsOnLeave; public byte Radius { get { return checked((byte)this.m_RoundRadius); } set { this.m_RoundRadius = (int)value; this.Invalidate(); } } public RoundButton() { this.Width = 120; this.Height = 50; this.ForeColor = Color.Green; this.FontHeight = 25; this.m_RoundRadius = 6; this.IsClicked = false; this.IsOnEnter = false; this.IsOnLeave = false; this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.ResizeRedraw, true); } private void Check() { checked { if ((double)this.m_RoundRadius > (double)this.Width / 2.0 | (double)this.m_RoundRadius > (double)this.Height / 2.0) { if ((double)this.Width / 2.0 > (double)this.Height / 2.0) { this.m_RoundRadius = (int)Math.Round((double)this.Height / 2.0); } else { this.m_RoundRadius = (int)Math.Round((double)this.Width / 2.0); } } else if (this.m_RoundRadius < 0) { this.m_RoundRadius = 0; } } } protected override void OnParentBackColorChanged(EventArgs e) { this.Invalidate(); } protected override void OnPaint(PaintEventArgs e) { checked { try { this.Check(); Graphics graphics = e.Graphics; Rectangle rect = new Rectangle(e.ClipRectangle.Left + this.m_RoundRadius, e.ClipRectangle.Top, e.ClipRectangle.Right - 2 * this.m_RoundRadius, e.ClipRectangle.Bottom); Rectangle rect2 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top + this.m_RoundRadius, e.ClipRectangle.Right, e.ClipRectangle.Bottom - 2 * this.m_RoundRadius); Rectangle rect3 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius); Rectangle rect4 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_RoundRadius, e.ClipRectangle.Top, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius); Rectangle rect5 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Bottom - 2 * this.m_RoundRadius, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius - 1); Rectangle rect6 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_RoundRadius, e.ClipRectangle.Bottom - 2 * this.m_RoundRadius, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius - 1); if (Operators.CompareString(this.Parent.GetType().Name, typeof(RoundPanel).Name, true) == 0) { graphics.Clear(this.Parent.ForeColor); } else { graphics.Clear(this.Parent.BackColor); } graphics.SmoothingMode = SmoothingMode.AntiAlias; Color color = Color.WhiteSmoke; if (this.IsOnEnter) { color = Color.LightGreen; } else if (this.IsOnLeave & !this.IsClicked) { color = this.m_OldBkColor; } else if (this.IsClicked) { color = this.BackColor; } else { color = this.BackColor; } Brush brush = new SolidBrush(color); graphics.FillRectangle(brush, rect); graphics.FillRectangle(brush, rect2); if (this.m_RoundRadius != 0) { graphics.FillPie(brush, rect3, 0f, 360f); graphics.FillPie(brush, rect4, 0f, 360f); graphics.FillPie(brush, rect5, 0f, 360f); graphics.FillPie(brush, rect6, 0f, 360f); } PointF point = unchecked(new PointF((float)((double)this.Width / 2.0 - (double)graphics.MeasureString(this.Text, this.Font).ToSize().Width / 2.0), (float)((double)this.Height / 2.0 - (double)graphics.MeasureString(this.Text, this.Font).ToSize().Height / 2.0))); Brush brush2 = new SolidBrush(this.ForeColor); graphics.DrawString(this.Text, this.Font, brush2, point); brush2.Dispose(); Image image = this.Image; Point point2 = new Point((int)Math.Round(unchecked((double)e.ClipRectangle.Width / 2.0 - (double)this.Image.Width / 2.0)), (int)Math.Round(unchecked((double)e.ClipRectangle.Height / 2.0 - (double)this.Image.Height / 2.0))); graphics.DrawImage(this.Image, point2); brush.Dispose(); } catch (Exception arg_409_0) { ProjectData.SetProjectError(arg_409_0); ProjectData.ClearProjectError(); } } } protected override void OnBackColorChanged(EventArgs e) { this.IsOnEnter = false; this.m_OldBkColor = this.BackColor; this.Invalidate(); } protected override void OnEnabledChanged(EventArgs e) { this.Invalidate(); } protected override void OnMouseEnter(EventArgs e) { if (!this.Enabled) { return; } this.m_OldBkColor = this.BackColor; this.IsOnEnter = true; this.IsOnLeave = false; this.Invalidate(); } protected override void OnMouseLeave(EventArgs e) { this.IsOnEnter = false; this.IsOnLeave = true; this.Invalidate(); } protected override void OnClick(EventArgs e) { base.OnClick(e); this.IsClicked = true; this.IsOnEnter = false; this.Invalidate(); } } }