//渲染图片区域 下拉菜单左边的图片区域 protected override void OnRenderImageMargin(ToolStripRenderEventArgs e) { //base.OnRenderImageMargin(e); //屏蔽掉左边图片竖条 Rectangle recback = e.AffectedBounds; recback.Width += 2; LinearGradientBrush lb = new LinearGradientBrush(e.AffectedBounds, BaseColor, BaseColor, LinearGradientMode.Horizontal); e.Graphics.FillRectangle(lb, recback); if (e.AffectedBounds.Height > 30) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Near; Rectangle rec = e.AffectedBounds; rec.X += 2; //rec.Width -= 1; Color fc = Color.FromArgb(71, 71, 71); if (BaseColor.R + BaseColor.B + BaseColor.G <= 280) { fc = Color.White; } e.Graphics.DrawString("BApim", new Font("Nina", 9f, FontStyle.Bold), new SolidBrush(fc), rec, sf); } e.Graphics.DrawLine(new Pen(ColorClass.GetColor(BaseColor, 0, -30, -30, -30)), new Point(recback.Width + recback.X, recback.Y), new Point(recback.Width + recback.X, recback.Y + recback.Height)); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rec = new Rectangle(0, 0, Width - 1, Height - 1); GraphicsPath path = GetGraphicPath.CreatePath(rec, 23, RoundStyle.None, true); g.FillPath(new SolidBrush(Color.White), path); g.DrawPath(new Pen(_borderColor), path); rec.Offset(0, 1); g.DrawRectangle(new Pen(_borderColor), rec); //path = GetGraphicPath.CreatePathTOP(rec, 19, false, 45); //g.DrawPath(new Pen(ColorClass.GetColor(_borderColor, 0, -20, -20, -20)), path); recDrop = new Rectangle(Width - 28, 5, 20, 16); //if (_mouse) //{ Rectangle recDrop1 = new Rectangle(Width - 26, 0, 28, 23); GraphicsPath pathDrop = GetGraphicPath.CreateVPath(recDrop1); g.DrawPath(new Pen(ColorClass.GetColor(_borderColor, 0, -20, -20, -20), 3), pathDrop); //} }
public JMDateList() { InitializeComponent(); _zyear = DateTime.Now.Year; _DaType = DateListType.Month; _month = DateTime.Now.Month; _moveColor = ColorClass.GetColor(this.BackColor, 255, -10, -10, -10); _selectColor = ColorClass.GetColor(this.BackColor, 255, -20, -20, -20); }
//渲染边框 不绘制边框 protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { //base.OnRenderToolStripBorder(e); Rectangle rec = e.AffectedBounds; rec.Width -= 1; rec.Height -= 1; e.Graphics.DrawRectangle(new Pen(ColorClass.GetColor(BaseColor, 0, -30, -30, -30)), rec); }
public JMRadioButton() : base() { SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); _BorderColor = ColorClass.GetBColor(); _HotColor = ColorClass.GetColor(_BorderColor, _BorderColor.A, 50, 50, 50); }
private void RenderConboBoxDropDownButton( Graphics g, Rectangle buttonRect, ControlState state) { Color baseColor; Color backColor = Color.FromArgb(160, 250, 250, 250); Color borderColor = base.Enabled ? _borderColor : SystemColors.ControlDarkDark; Color arrowColor = base.Enabled ? _arrowColor : SystemColors.ControlDarkDark; Rectangle rect = buttonRect; if (base.Enabled) { switch (state) { case ControlState.Hover: baseColor = ColorClass.GetColor( _baseColor, 0, -33, -22, -13); break; case ControlState.Pressed: baseColor = ColorClass.GetColor( _baseColor, 0, -65, -47, -25); break; default: baseColor = _baseColor; break; } } else { baseColor = SystemColors.ControlDark; } rect.Inflate(-1, -1); RenderScrollBarArrowInternal( g, rect, baseColor, borderColor, backColor, arrowColor, RoundStyle.None, true, false, ArrowDirection.Down, LinearGradientMode.Vertical); }
internal void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, float basePosition, bool drawBorder, LinearGradientMode mode) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; colors[0] = ColorClass.GetColor(baseColor, 0, 35, 24, 9); colors[1] = ColorClass.GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = ColorClass.GetColor(baseColor, 0, 68, 69, 54); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; g.FillRectangle(brush, rect); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } if (drawBorder) { using (Pen pen = new Pen(borderColor)) { g.DrawRectangle(pen, rect); } } }
private void DrawChart(Graphics g) { int chartW = Width - paddings * 2; int chartH = Height - paddings * 2; int spacew = chartW / (m_values.Length + 1); Int64 maxV = 10; int dc = 5; while (maxV < maxValue) { maxV *= dc; dc = dc == 5 ? 2 : 5; } decimal oneH = Convert.ToDecimal(chartH) / Convert.ToDecimal(maxV); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisPath; for (int i = 1; i < (m_values.Length + 1); i++) { int sw = paddings + i * spacew; decimal tvalue = m_values[i - 1]; float cyliH = Convert.ToSingle(oneH * tvalue); if (cyliH > 0) { RectangleF rect = new RectangleF(sw - 10, Height - paddings - cyliH, 20, cyliH); Color itc = Color.Black; if (m_pieColor.Length < i) { itc = ColorClass.GetColor(m_pieColor[(i - 1) % (m_pieColor.Length - 1)], -20, 20, 6, 30); } else { itc = m_pieColor[i - 1]; } g.FillRectangle(new SolidBrush(itc), rect); } RectangleF rects = new RectangleF(sw - paddings/2, Height - paddings - cyliH - 20, paddings, 20); g.DrawString(tvalue.ToString("N2"), Font, new SolidBrush(this.ForeColor), rects, sf); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; //228, 241, 213 Color bc = Color.FromArgb(250, 250, 250); Rectangle _rect = new Rectangle(1, 1, Width - 1, Height - 1); g.FillRectangle(new SolidBrush(bc), _rect); //Color acolor = ColorClass.GetColor(_baseColor, 0, 0, -8, -20); //ControlPaintClass.RenderBackgroundInternal(g, rect, acolor, acolor, acolor, RoundStyle.None, _radius, 0.01F, true, false, LinearGradientMode.); //Rectangle _bottom = new Rectangle(_rect.Left + 1, _rect.Bottom, _rect.Right, 1); //Rectangle _right = new Rectangle(_rect.Right - 1, _rect.Top + 1, 1, _rect.Bottom); //LinearGradientBrush bottomBrush = new LinearGradientBrush(_bottom, Color.Black, Color.FromArgb(60, 241, 242, 211), LinearGradientMode.Vertical); //LinearGradientBrush rightBrush = new LinearGradientBrush(_right, Color.Black, Color.FromArgb(60, 241, 242, 211), LinearGradientMode.Horizontal); //GraphicsPath _bottomPath = new GraphicsPath(); //_bottomPath.AddLine(_rect.Left + 1, _rect.Bottom, _rect.Right, _rect.Bottom); //_bottomPath.AddLine(_rect.Right, _rect.Bottom, _rect.Right + 1, _rect.Bottom + 1); //_bottomPath.AddLine(_rect.Right + 1, _rect.Bottom + 1, _rect.Left + 1, _rect.Bottom + 1); //_bottomPath.AddLine(_rect.Left + 1, _rect.Bottom + 1, _rect.Left + 1, _rect.Bottom); //_bottomPath.CloseAllFigures(); //GraphicsPath _rightPath = new GraphicsPath(); //_rightPath.AddLine(_rect.Right, _rect.Top + 1, _rect.Right + 1, _rect.Top + 1); //_rightPath.AddLine(_rect.Right + 1, _rect.Top + 1, _rect.Right + 1, _rect.Bottom + 1); //_rightPath.AddLine(_rect.Right + 1, _rect.Bottom + 1, _rect.Right, _rect.Bottom); //_rightPath.AddLine(_rect.Right, _rect.Bottom, _rect.Right, _rect.Top + 1); //_rightPath.CloseAllFigures(); //e.Graphics.FillPath(bottomBrush, _bottomPath); //e.Graphics.FillPath(rightBrush, _rightPath); //191,212,211 _rect = new Rectangle(1, 1, 20, Height - 1); Color acolor = ColorClass.GetColor(bc, 0, -20, -20, -20); //ControlPaintClass.RenderBackgroundInternal(g, rect, acolor, acolor, Color.FromArgb(128, 210, 210, 210), RoundStyle.None, _radius, 0.01F, false, false, LinearGradientMode.Vertical); g.FillRectangle(new SolidBrush(acolor), _rect); g.DrawRectangle(new Pen(Color.Silver), new Rectangle(0, 0, Width - 1, Height - 1)); //rect = new Rectangle(0, 0, Width, Height); //GraphicsPath path = ControlPaintClass.CreatePath(rect, _radius, RoundStyle.All, false); //this.Region = new Region(path); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); GraphicsPath aa = GetGraphicPath.CreatePath(rect, _ZRadian, RoundStyle.All, false); //aa.CloseFigure(); g.FillPath(new SolidBrush(Color.White), aa); g.DrawPath(new Pen(_borderColor), aa); rect.Offset(0, 1); aa = GetGraphicPath.CreatePathTOP(rect, _ZRadian, false, 45); g.DrawPath(new Pen(ColorClass.GetColor(_borderColor, 0, -20, -20, -20)), aa); }
private void RenderConboBoxBorder( Graphics g, Rectangle rect) { Color borderColor = base.Enabled ? _borderColor : SystemColors.ControlDarkDark; using (Pen pen = new Pen(borderColor)) { rect.Width--; rect.Height--; g.DrawRectangle(pen, rect); if (isFouc == ControlState.Hover && base.Enabled) { Color cl = ColorClass.GetColor(borderColor, borderColor.A, 50, 50, 50); rect.Width -= 2; rect.Height -= 2; rect.X++; rect.Y++; g.DrawRectangle(new Pen(cl), rect); } } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { try { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; //高质量 g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量 if (Width <= 0 || Height <= 0) { return; } if (IsMouseDown) { Color cloh = Color.FromArgb(255, 200, 200, 200); Rectangle rec1 = new Rectangle(0, 0, Width, Height); LinearGradientBrush lb = new LinearGradientBrush(rec1, ColorClass.GetColor(cloh, -135, 0, 0, 0), ColorClass.GetColor(cloh, -253, 0, 0, 0), LinearGradientMode.Vertical); if (Width <= 0 || Height <= 0) { return; } g.FillRectangle(lb, rec1); g.DrawLine(new Pen(Color.FromArgb(120, 50, 50, 50)), new Point(0, 0), new Point(Width, 0)); } if (isMouseOn) { Color cloh = Color.FromArgb(255, 255, 255, 255); Rectangle rec1 = new Rectangle(0, 0, Width, Height); LinearGradientBrush lb = new LinearGradientBrush(rec1, ColorClass.GetColor(cloh, -135, 0, 0, 0), ColorClass.GetColor(cloh, -253, 0, 0, 0), LinearGradientMode.Vertical); if (Width <= 0 || Height <= 0) { return; } g.FillRectangle(lb, rec1); g.DrawLine(new Pen(Color.FromArgb(120, 50, 50, 50)), new Point(0, 0), new Point(Width, 0)); } if (img != null) { int x = (Width - img.Width) / 2; int y = (Height - 20 - img.Height) / 2; if (Width <= 0 || Height <= 0) { return; } Rectangle rec = new Rectangle(new Point(x, y), img.Size); g.DrawImage(img, rec); } if (IsNew) { //g.FillEllipse(new SolidBrush(Color.Red), new Rectangle(55, 20, 10, 10)); g.DrawImage(Properties.Resources._new, new Rectangle(this.Width - 12, 2, 10, 10)); } Rectangle rectext = new Rectangle(_ZTextLocation, new Size(toolSize.Width, 30)); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Near; sf.Alignment = StringAlignment.Center; if (Width <= 0 || Height <= 0) { return; } g.DrawString(ZText, this.Font, new SolidBrush(ForeColor), rectext, sf); } catch { Invalidate(); } }
/// <summary> /// 创建控件与颜色 /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; #region 平面显示 if (_JMDisplayStyle.ToString() == "None") { //矩形默认颜色 Rectangle Rect = new Rectangle(new Point(0, 0), new Size(this.Width - 1, this.Height - 1)); //矩形液体颜色 Rectangle YTRect; //百分值 float Percentage = (!_JMSFTransverse ? this.Height : this.Width) / Convert.ToSingle(100); //液体高度 int LiquidHeight = Convert.ToInt32(Percentage * _JMPercentage); //竖向显示 if (!_JMSFTransverse) { YTRect = new Rectangle(new Point(0, this.Height - LiquidHeight), new Size(this.Width - 1, LiquidHeight - 1)); } else//横向显示 { YTRect = new Rectangle(new Point(0, 0), new Size(LiquidHeight - 1, this.Height - 1)); } //画底 g.DrawRectangle(new Pen(new SolidBrush(_JMFlatMRColor)), Rect); g.FillRectangle(new SolidBrush(_JMFlatMRColor), Rect); //画液体 if (LiquidHeight > 0) { g.DrawRectangle(new Pen(new SolidBrush(_JMFlatColor)), YTRect); g.FillRectangle(new SolidBrush(_JMFlatColor), YTRect); } if (_JMSFTransverse) { Rectangle textRect = new Rectangle(2, 0, Width - 1, Height); Rectangle valueRect = new Rectangle(2, 0, YTRect.Width - 2, Height); StringFormat sformat = new StringFormat(); sformat.LineAlignment = StringAlignment.Center; //画标题 //计算标题+内容长度是否大于液体长度 SizeF sf = g.MeasureString(_JMJDBiaoTi + " " + _JMJDText, this.Font); if (sf.Width + 4 > YTRect.Width)//大于 { //正常画标题和内容 g.DrawString(_JMJDBiaoTi + " " + _JMJDText, this.Font, new SolidBrush(_JMJDForeColor), textRect, sformat); } else//小于 { //画标题 g.DrawString(_JMJDBiaoTi, this.Font, new SolidBrush(_JMJDForeColor), textRect, sformat); //对齐方式 sformat.Alignment = StringAlignment.Far; //画内容 g.DrawString(_JMJDText, this.Font, new SolidBrush(_JMJDForeColor), valueRect, sformat); } } } #endregion #region 圆柱体 else if (_JMDisplayStyle.ToString() == "Cylinder") { #region 竖向显示 if (!_JMSFTransverse) { //中间透明区域中间渐变颜色 Color a = Color.FromArgb(100, 255, 255, 255); //中间透明区域起始和结束渐变颜色 Color b = Color.FromArgb(20, 160, 160, 160); //中间透明区域上边 Rectangle RecUp3 = new Rectangle(new Point(1, 11), new Size(this.Width - 3, 15)); //中间透明区域下边 Rectangle RecDown3 = new Rectangle(new Point(1, this.Height - 21), new Size(this.Width - 3, 15)); //最上面椭圆矩形区域上边 Rectangle RecUp1 = new Rectangle(new Point(1, 2), new Size(this.Width - 3, 15)); //最上面椭圆矩形区域下边 Rectangle RecUp2 = new Rectangle(new Point(1, 5), new Size(this.Width - 3, 15)); //最下面椭圆矩形区域下边 Rectangle RecDown1 = new Rectangle(new Point(1, this.Height - 17), new Size(this.Width - 3, 15)); //最下面椭圆矩形区域上边 Rectangle RecDown2 = new Rectangle(new Point(1, this.Height - 21), new Size(this.Width - 3, 15)); //直线矩形内渐变颜色 LinearGradientBrush lb = ColorGradient(new Rectangle(1, 13, this.Width - 3, this.Height - 13), b, a, b, LinearGradientMode.Horizontal); //最上面椭圆渐变颜色 LinearGradientBrush lb1 = ColorGradient(new Rectangle(1, 2, this.Width - 3, 15), _JMTopDownColor1, _JMTopDownColor2, _JMTopDownColor3, _JMTopDownColor4, _JMTopDownColor5, LinearGradientMode.Horizontal); //最下面椭圆渐变颜色 LinearGradientBrush lb2 = ColorGradient(new Rectangle(1, this.Height - 27, this.Width - 3, 15), _JMTopDownColor1, _JMTopDownColor2, _JMTopDownColor3, _JMTopDownColor4, _JMTopDownColor5, LinearGradientMode.Horizontal); //中间液体椭圆区域渐变颜色 LinearGradientBrush lb5 = ColorGradient(new Rectangle(1, 30, this.Width - 3, 15), _JMMiddleLiquid1, _JMMiddleLiquid2, _JMMiddleLiquid3, LinearGradientMode.Horizontal); //中间液体顶部椭圆渐变颜色 LinearGradientBrush lb6 = ColorGradient(new Rectangle(1, 45, this.Width - 3, 15), _JMLiquidTop1, _JMLiquidTop2, _JMLiquidTop3, LinearGradientMode.Horizontal); //最上面椭圆(即椭圆的盖) LinearGradientBrush lb7 = ColorGradient(new Rectangle(1, 2, this.Width - 3, 15), _JMTopColor1, _JMTopColor2, _JMTopColor3, LinearGradientMode.Horizontal); //液体底部椭圆渐变 LinearGradientBrush lb8 = ColorGradient(new Rectangle(1, this.Height - 21, this.Width - 3, 15), _JMLiquidDown1, _JMLiquidDown2, _JMLiquidDown3, LinearGradientMode.Horizontal); //中间透明区域 GraphicsPath rr = new GraphicsPath(); rr.AddArc(RecUp3, 0, -180); rr.AddArc(RecDown3, 180, -180); rr.CloseFigure(); g.FillPath(lb, rr); if (_JMPercentage > 0) { //百分值 float Percentage = (this.Height - 5 - 21) / Convert.ToSingle(100); //液体高度 int LiquidHeight = Convert.ToInt32(Percentage * _JMPercentage); //中间液体下边Y坐标 int LiquidYZhou = this.Height - 21; //中间液体椭圆矩形区域上边 Rectangle recEllipse3 = new Rectangle(new Point(1, LiquidYZhou - LiquidHeight - 1), new Size(this.Width - 3, 15)); //中间液体椭圆矩形区域下边 Rectangle recEllipse4 = new Rectangle(new Point(1, LiquidYZhou), new Size(this.Width - 3, 15)); //中间液体的区域与填充 GraphicsPath gp = new GraphicsPath(); gp.AddArc(recEllipse3, 0, 180); gp.AddArc(recEllipse4, 180, -180); gp.CloseFigure(); g.FillPath(lb5, gp); //中间液体椭圆顶部--椭圆线的颜色、起始坐标、宽度高度 g.DrawEllipse(new Pen(Color.FromArgb(40, 0, 0, 0), 1), recEllipse3); //中间液体椭圆顶部--渐变起始坐标、渐变结束坐标、起始颜色、结束颜色,--要填充的椭圆起始坐标、椭圆宽度高度 g.FillEllipse(lb6, recEllipse3); if (LiquidYZhou - LiquidHeight + 12 <= this.Height - 21 - 12 + 7) { //液体底部椭圆 g.DrawEllipse(new Pen(Color.FromArgb(200, 200, 200), 1), RecDown2); //液体底部椭圆渐变填充 g.FillEllipse(lb8, RecDown2); } } else { //液体底部椭圆 g.DrawEllipse(new Pen(Color.FromArgb(200, 200, 200), 1), RecDown2); } //最上面椭圆渐变(即椭圆的盖) g.FillEllipse(lb7, RecUp1); //最上面椭圆区域 GraphicsPath qq = new GraphicsPath(); qq.AddArc(RecUp1, 0, 180); qq.AddArc(RecUp2, 180, -180); qq.CloseFigure(); g.FillPath(lb1, qq); //最下面椭圆区域 GraphicsPath yy = new GraphicsPath(); yy.AddArc(RecDown1, 0, 180); yy.AddArc(RecDown2, 180, -180); yy.CloseFigure(); g.FillPath(lb2, yy); //描边 GraphicsPath gp1 = new GraphicsPath(); gp1.AddArc(RecUp1, 0, -180); gp1.AddArc(RecDown1, 180, -180); gp1.CloseFigure(); g.DrawPath(new Pen(Color.FromArgb(70, 255, 255, 255)), gp1); } #endregion #region 横向显示 else { //中间透明区域中间渐变颜色 Color a = Color.FromArgb(100, 255, 255, 255); //中间透明区域起始和结束渐变颜色 Color b = Color.FromArgb(20, 160, 160, 160); //中间透明区域左边 Rectangle RecUp3 = new Rectangle(new Point(4, 2), new Size(15, this.Height - 3)); //中间透明区域右边 Rectangle RecDown3 = new Rectangle(new Point(this.Width - 22, 2), new Size(15, this.Height - 3)); //最右面椭圆矩形区域右边 Rectangle RecUp1 = new Rectangle(new Point(this.Width - 19, 2), new Size(15, this.Height - 3)); //最右面椭圆矩形区域左边 Rectangle RecUp2 = new Rectangle(new Point(this.Width - 22, 2), new Size(15, this.Height - 3)); //最左面椭圆矩形区域左边 Rectangle RecDown1 = new Rectangle(new Point(1, 2), new Size(15, this.Height - 3)); //最左面椭圆矩形区域右边 Rectangle RecDown2 = new Rectangle(new Point(4, 2), new Size(15, this.Height - 3)); //中间透明区域渐变颜色 LinearGradientBrush lb = ColorGradient(new Rectangle(4, 2, this.Width - 22, this.Height - 3), b, a, b, LinearGradientMode.Vertical); //最右面椭圆渐变颜色 LinearGradientBrush lb1 = ColorGradient(new Rectangle(this.Width - 19, 2, 15, this.Height - 3), _JMTopDownColor1, _JMTopDownColor2, _JMTopDownColor3, _JMTopDownColor4, _JMTopDownColor5, LinearGradientMode.Vertical); //最左面椭圆渐变颜色 LinearGradientBrush lb2 = ColorGradient(new Rectangle(4, 2, 15, this.Height - 3), _JMTopDownColor1, _JMTopDownColor2, _JMTopDownColor3, _JMTopDownColor4, _JMTopDownColor5, LinearGradientMode.Vertical); //中间液体椭圆区域渐变颜色 LinearGradientBrush lb5 = ColorGradient(new Rectangle(4, 2, 15, this.Height - 3), _JMMiddleLiquid1, _JMMiddleLiquid2, _JMMiddleLiquid3, LinearGradientMode.Vertical); //最右面椭圆(即椭圆的盖) LinearGradientBrush lb7 = ColorGradient(new Rectangle(this.Width - 19, 2, 15, this.Height - 3), _JMTopColor1, _JMTopColor2, _JMTopColor3, LinearGradientMode.Vertical); //液体底部椭圆渐变 LinearGradientBrush lb8 = ColorGradient(new Rectangle(4, 2, 15, this.Height - 3), _JMLiquidDown1, _JMLiquidDown2, _JMLiquidDown3, LinearGradientMode.Vertical); //中间透明区域 GraphicsPath rr = new GraphicsPath(); rr.AddArc(RecUp3, 270, 180); rr.AddArc(RecDown3, 90, 180); rr.CloseFigure(); g.FillPath(lb, rr); if (_JMPercentage > 0) { //百分值 float Percentage = (this.Width - 4 - 22) / Convert.ToSingle(100); //液体高度 int LiquidHeight = Convert.ToInt32(Percentage * _JMPercentage); //中间液体左边X坐标 int LiquidXZhou = 4; //中间液体椭圆矩形区域左边 Rectangle recEllipse3 = new Rectangle(new Point(4, 2), new Size(15, this.Height - 3)); //中间液体椭圆矩形区域右边 Rectangle recEllipse4 = new Rectangle(new Point(LiquidXZhou + LiquidHeight, 2), new Size(15, this.Height - 3)); //中间液体顶部椭圆渐变颜色 LinearGradientBrush lb6 = ColorGradient(new Rectangle(LiquidXZhou - LiquidHeight, 2, 15, this.Height - 3), _JMLiquidTop1, _JMLiquidTop2, _JMLiquidTop3, LinearGradientMode.Vertical); //中间液体的区域与填充 GraphicsPath gp = new GraphicsPath(); gp.AddArc(recEllipse3, 90, 180); gp.AddArc(recEllipse4, -90, -180); gp.CloseFigure(); g.FillPath(lb5, gp); //中间液体椭圆顶部--椭圆线的颜色、起始坐标、宽度高度 g.DrawEllipse(new Pen(Color.FromArgb(40, 0, 0, 0), 1), recEllipse4); //中间液体椭圆顶部--渐变起始坐标、渐变结束坐标、起始颜色、结束颜色,--要填充的椭圆起始坐标、椭圆宽度高度 g.FillEllipse(lb6, recEllipse4); if (4 + 15 <= LiquidXZhou + LiquidHeight) { //液体底部椭圆 g.DrawEllipse(new Pen(Color.FromArgb(200, 200, 200), 1), RecDown2); //液体底部椭圆渐变填充 g.FillEllipse(lb8, RecDown2); } } else { //液体底部椭圆 g.DrawEllipse(new Pen(Color.FromArgb(200, 200, 200), 1), RecDown2); } //最右面椭圆渐变(即椭圆的盖) g.FillEllipse(lb7, RecUp1); //最右面椭圆区域 GraphicsPath qq = new GraphicsPath(); qq.AddArc(RecUp1, 90, 180); qq.AddArc(RecUp2, -90, -180); qq.CloseFigure(); g.FillPath(lb1, qq); //最左面椭圆区域 GraphicsPath yy = new GraphicsPath(); yy.AddArc(RecDown1, -270, 180); yy.AddArc(RecDown2, -90, -180); yy.CloseFigure(); g.FillPath(lb2, yy); //描边 GraphicsPath gp1 = new GraphicsPath(); gp1.AddArc(RecUp1, 90, -180); gp1.AddArc(RecDown1, -90, -180); gp1.CloseFigure(); g.DrawPath(new Pen(Color.FromArgb(70, 255, 255, 255)), gp1); } #endregion } #endregion #region 立方体 else if (_JMDisplayStyle.ToString() == "Cube") { //顶部多边形坐标、颜色填充宽/高度 Rectangle rect = new Rectangle(18, 1, this.Width - 1, 17); //左侧多边形坐标、颜色填充宽/高度 Rectangle rect1 = new Rectangle(18, 1, 17, this.Height - 1); //右侧多边形坐标、颜色填充宽/高度 Rectangle rect2 = new Rectangle(this.Width - 1, 1, 17, this.Height - 1); //底部多边形坐标、颜色填充宽/高度 Rectangle rect3 = new Rectangle(18, this.Height - 17, this.Width - 1, 17); //后面矩形坐标、颜色填充宽/高度 Rectangle rect4 = new Rectangle(18, 17, this.Width - 18 * 2, this.Height - 18); //顶部多边形填充颜色、填充样式 LinearGradientBrush lb = new LinearGradientBrush(rect, _JMCubeColor1, _JMCubeColor2, LinearGradientMode.Vertical); //左侧多边形填充颜色、填充样式 LinearGradientBrush lb1 = new LinearGradientBrush(rect1, _JMCubeBackColor, _JMCubeBackColor, LinearGradientMode.Vertical); //右侧多边形填充颜色、填充样式 LinearGradientBrush lb2 = new LinearGradientBrush(rect2, _JMCubeBackColor, _JMCubeBackColor, LinearGradientMode.Vertical); //底部多边形填充颜色、填充样式 LinearGradientBrush lb3 = new LinearGradientBrush(rect3, _JMCubeBackColor, _JMCubeBackColor, LinearGradientMode.Vertical); //后面矩形填充颜色、填充样式 LinearGradientBrush lb4 = new LinearGradientBrush(rect4, _JMCubeBackColor, _JMCubeBackColor, LinearGradientMode.Vertical); //后面矩形填充颜色 g.FillRectangle(lb4, rect4); //左侧多边形填充颜色 g.FillPolygon(lb1, new Point[] { new Point(18, 1), new Point(1, 17), new Point(1, this.Height - 1), new Point(18, this.Height - 17) }); //底部多边形填充颜色 g.FillPolygon(lb3, new Point[] { new Point(18, this.Height - 17), new Point(1, this.Height - 1), new Point(this.Width - 18, this.Height - 1), new Point(this.Width - 1, this.Height - 17) }); //右侧多边形填充颜色 g.FillPolygon(lb2, new Point[] { new Point(this.Width - 1, 1), new Point(this.Width - 18, 17), new Point(this.Width - 18, this.Height - 1), new Point(this.Width - 1, this.Height - 17) }); //左 g.DrawPolygon(new Pen(new SolidBrush(ColorClass.GetColor(Color.Aqua, -180, 0, 0, 255))), new Point[] { new Point(18, 1), new Point(1, 17), new Point(1, this.Height - 1), new Point(18, this.Height - 17) }); //底 g.DrawPolygon(new Pen(new SolidBrush(ColorClass.GetColor(Color.Aqua, -100, 0, 0, 255))), new Point[] { new Point(18, this.Height - 17), new Point(1, this.Height - 1), new Point(this.Width - 18, this.Height - 1), new Point(this.Width - 1, this.Height - 17) }); if (_JMPercentage > 0) { //百分值 float Percentage = (this.Height - 17 - 2) / Convert.ToSingle(100); //液体高度 CubeLiquidHeight = Convert.ToInt32(Percentage * _JMPercentage); //中间液体下边X坐标 int LiquidXZhou = this.Width - 1; //前面液体矩形坐标、颜色填充宽/高度 Rectangle rect5 = new Rectangle(1, this.Height - (CubeLiquidHeight + 2), this.Width - (18 + 1), this.Height - (this.Height - CubeLiquidHeight - 1)); //前面矩形填充颜色 g.FillRectangle(new SolidBrush(_JMCubeLiquidColor), rect5); //右侧液体多边形坐标、颜色填充 g.FillPolygon(new SolidBrush(_JMCubeLiquidColor), new Point[] { new Point(this.Width - 18, this.Height - (CubeLiquidHeight + 1)), new Point(this.Width - 1, this.Height - (CubeLiquidHeight + 1) - 17), new Point(this.Width - 1, this.Height - 17), new Point(this.Width - 18, this.Height - 1) }); //液体顶部多边形坐标、颜色填充 g.FillPolygon(new SolidBrush(_JMCubeLiquidColor), new Point[] { new Point(1, this.Height - (CubeLiquidHeight + 2)), new Point(18, this.Height - (CubeLiquidHeight + 1) - 17), new Point(this.Width - 1, this.Height - (CubeLiquidHeight + 1) - 17), new Point(this.Width - 18, this.Height - (CubeLiquidHeight + 2)) }); } //顶部多边形填充颜色 g.FillPolygon(lb, new Point[] { new Point(18, 1), new Point(1, 17), new Point(this.Width - 18, 17), new Point(this.Width - 1, 1) }); //右 g.DrawPolygon(new Pen(new SolidBrush(Color.Aqua)), new Point[] { new Point(this.Width - 1, 1), new Point(this.Width - 18, 17), new Point(this.Width - 18, this.Height - 1), new Point(this.Width - 1, this.Height - 17) }); //顶 g.DrawPolygon(new Pen(new SolidBrush(Color.Aqua)), new Point[] { new Point(18, 1), new Point(1, 17), new Point(this.Width - 18, 17), new Point(this.Width - 1, 1) }); //描边 g.DrawPolygon(new Pen(new SolidBrush(Color.Aqua)), new Point[] { new Point(18, 1), new Point(1, 17), new Point(1, this.Height - 1), new Point(this.Width - 18, this.Height - 1), new Point(this.Width - 1, this.Height - 17), new Point(this.Width - 1, 1) }); } #endregion }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (base.Panel1Collapsed || base.Panel2Collapsed) { return; } Graphics g = e.Graphics; Rectangle rect = base.SplitterRectangle; if (rect.Width <= 0 || rect.Height <= 0) { return; } bool bHorizontal = base.Orientation == Orientation.Horizontal; LinearGradientMode gradientMode = bHorizontal ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; using (LinearGradientBrush brush = new LinearGradientBrush( rect, ColorClass.GetColor(_zBaseColor, 0, 100, 35, 0), _zBaseColor, gradientMode))//Color.FromArgb(105, 200, 254) { Blend blend = new Blend(); blend.Positions = new float[] { 0f, .5f, 1f }; blend.Factors = new float[] { .5F, 1F, .5F }; brush.Blend = blend; g.FillRectangle(brush, rect); } if (_collapsePanel == CollapsePanel.None) { return; } Rectangle arrowRect; Rectangle topLeftRect; Rectangle bottomRightRect; CalculateRect( CollapseRect, out arrowRect, out topLeftRect, out bottomRightRect); ArrowDirection direction = ArrowDirection.Left; switch (_collapsePanel) { case CollapsePanel.Panel1: if (bHorizontal) { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Down : ArrowDirection.Up; } else { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Right : ArrowDirection.Left; } break; case CollapsePanel.Panel2: if (bHorizontal) { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Up : ArrowDirection.Down; } else { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Left : ArrowDirection.Right; } break; } Color foreColor = _mouseState == ControlState.Hover ? _zArrowColor : ColorClass.GetColor(_zArrowColor, 0, 60, 70, 90); using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g)) { ControlPaintClass.RenderGrid(g, topLeftRect, new Size(3, 3), foreColor); ControlPaintClass.RenderGrid(g, bottomRightRect, new Size(3, 3), foreColor); using (Brush brush = new SolidBrush(foreColor)) { ControlPaintClass.RenderArrowInternal( g, arrowRect, direction, brush); } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(Margin.Left, Margin.Top, Width - Margin.Left - Margin.Right, Height - Margin.Top - Margin.Bottom); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; Color fcolor = _JMTextColor; Font ffont = this.Font; int imgX = 0; int imgY = 0; if (SFVisibleEffect) { fcolor = ColorClass.GetColor(fcolor, 0, 50, 50, 50); ffont = new Font(Font, FontStyle.Underline); } switch (_TextImageRelation) { case TextImageRelation.ImageAboveText: imgX = (Width - JMImageSize.Width) / 2; imgY = rect.Y; break; case TextImageRelation.ImageBeforeText: imgX = rect.X; imgY = (Height - JMImageSize.Height) / 2; sf.Alignment = StringAlignment.Near; rect.X += (JMImageSize.Width); rect.Width -= (JMImageSize.Width); break; case TextImageRelation.Overlay: imgX = (Width - JMImageSize.Width) / 2; imgY = (Height - JMImageSize.Height) / 2; break; case TextImageRelation.TextAboveImage: imgX = (Width - JMImageSize.Width) / 2; imgY = rect.Y + (rect.Height - JMImageSize.Height); break; case TextImageRelation.TextBeforeImage: imgX = rect.X + (rect.Width - JMImageSize.Width); imgY = (Height - JMImageSize.Height) / 2; sf.Alignment = StringAlignment.Far; rect.Width -= (JMImageSize.Width); break; default: imgX = (Width - JMImageSize.Width) / 2; imgY = (Height - JMImageSize.Height) / 2; break; } if (_JMImage != null) { g.DrawImage(_JMImage, new Rectangle(new Point(imgX, imgY), JMImageSize)); } g.DrawString(_JMText, ffont, new SolidBrush(fcolor), rect, sf); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); base.OnPaintBackground(e); Graphics g = e.Graphics; Rectangle radioButtonrect; Rectangle textRect; CalculateRect(out radioButtonrect, out textRect); g.SmoothingMode = SmoothingMode.AntiAlias; Color borderColor; Color innerBorderColor; Color checkColor; bool hover = false; if (Enabled) { switch (ControlState) { case ControlState.Hover: borderColor = _BorderColor; innerBorderColor = _BorderColor; checkColor = ColorClass.GetColor(_BorderColor, 0, 35, 24, 9); hover = true; break; case ControlState.Pressed: borderColor = _BorderColor; innerBorderColor = ColorClass.GetColor(_BorderColor, 0, -13, -8, -3); checkColor = ColorClass.GetColor(_BorderColor, 0, -35, -24, -9); hover = true; break; default: borderColor = _BorderColor; innerBorderColor = Color.Empty; checkColor = _BorderColor; break; } } else { borderColor = SystemColors.ControlDark; innerBorderColor = SystemColors.ControlDark; checkColor = SystemColors.ControlDark; } using (SolidBrush brush = new SolidBrush(Color.White)) { g.FillEllipse(brush, radioButtonrect); } if (hover) { using (Pen pen = new Pen(innerBorderColor, 2F)) { g.DrawEllipse(pen, radioButtonrect); } } if (Checked) { radioButtonrect.Inflate(-2, -2); using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(radioButtonrect); using (PathGradientBrush brush = new PathGradientBrush(path)) { brush.CenterColor = checkColor; brush.SurroundColors = new Color[] { Color.White }; Blend blend = new Blend(); blend.Positions = new float[] { 0f, 0.4f, 1f }; blend.Factors = new float[] { 0f, 0.4f, 1f }; brush.Blend = blend; g.FillEllipse(brush, radioButtonrect); } } radioButtonrect.Inflate(2, 2); } using (Pen pen = new Pen(borderColor)) { g.DrawEllipse(pen, radioButtonrect); } Color textColor = Enabled ? ForeColor : SystemColors.GrayText; TextRenderer.DrawText( g, Text, Font, textRect, textColor, TextFormat.GetTextFormatFlags(TextAlign, RightToLeft == RightToLeft.Yes)); }
protected virtual void OnPaintUpDownButton( UpDownButtonPaintEventArgs e) { Graphics g = e.Graphics; Rectangle rect = e.ClipRectangle; Color upButtonBaseColor = _baseColor; Color upButtonBorderColor = _borderColor; Color upButtonArrowColor = _arrowColor; Color downButtonBaseColor = _baseColor; Color downButtonBorderColor = _borderColor; Color downButtonArrowColor = _arrowColor; Rectangle upButtonRect = rect; upButtonRect.Y += 1; upButtonRect.Width -= 2; upButtonRect.Height = rect.Height / 2 - 2; Rectangle downButtonRect = rect; downButtonRect.Y = upButtonRect.Bottom + 2; downButtonRect.Height = rect.Height - upButtonRect.Bottom - 4; downButtonRect.Width -= 2; if (Enabled) { if (e.MouseOver) { if (e.MousePress) { if (e.MouseInUpButton) { upButtonBaseColor = ColorClass.GetColor(_baseColor, 0, -35, -24, -9); } else { downButtonBaseColor = ColorClass.GetColor(_baseColor, 0, -35, -24, -9); } } else { if (e.MouseInUpButton) { upButtonBaseColor = ColorClass.GetColor(_baseColor, 0, 35, 24, 9); } else { downButtonBaseColor = ColorClass.GetColor(_baseColor, 0, 35, 24, 9); } } } } else { upButtonBaseColor = SystemColors.Control; upButtonBorderColor = SystemColors.ControlDark; upButtonArrowColor = SystemColors.ControlDark; downButtonBaseColor = SystemColors.Control; downButtonBorderColor = SystemColors.ControlDark; downButtonArrowColor = SystemColors.ControlDark; } g.SmoothingMode = SmoothingMode.AntiAlias; Color backColor = Enabled ? base.BackColor : SystemColors.Control; using (SolidBrush brush = new SolidBrush(backColor)) { rect.Inflate(1, 1); g.FillRectangle(brush, rect); } RenderButton( g, upButtonRect, upButtonBaseColor, upButtonBorderColor, upButtonArrowColor, ArrowDirection.Up); RenderButton( g, downButtonRect, downButtonBaseColor, downButtonBorderColor, downButtonArrowColor, ArrowDirection.Down); UpDownButtonPaintEventHandler handler = base.Events[EventPaintUpDownButton] as UpDownButtonPaintEventHandler; if (handler != null) { handler(this, e); } }
/// <summary> /// 画饼图 /// </summary> /// <param name="g">画布</param> private void DrawChart(Graphics g) { CanMoveScroll = 0; Rectangle rec = new Rectangle(Padding.Left, Padding.Top, PieWidth, PieHeight);// //起始角度 float startAngle = 0f; //弧度 float sweepAngle = 0f; PointF startP = new PointF(PieWidth, PieOrigin.Y); PointF endP = new PointF(0, PieOrigin.Y); if (m_values == null) { Color itc = Color.Gray; sweepAngle = 360; g.FillPie(new SolidBrush(itc), rec, startAngle, sweepAngle); g.DrawPie(new Pen(Color.FromArgb(224, 224, 224)), rec, startAngle, sweepAngle); //画底部 if (startAngle < 180) { float endang = startAngle + sweepAngle > 180 ? 180 : startAngle + sweepAngle; GraphicsPath gpath = GetGraphicPath.CreatePathForCylinderSurfaceSection(rec, startAngle, endang, startP, endP, m_height3D); g.FillPath(new SolidBrush(ColorClass.GetColor(itc, 0, -80, -80, -80)), gpath); } Rectangle rectmx = new Rectangle(180, 20 + 3, 11, 11); g.DrawString("无数据", Font, new SolidBrush(ForeColor), new PointF(rectmx.X + rectmx.Width + 5, 20 + 3)); jmButtonTriangle2.Visible = false; } else { //画所有饼块 for (int i = 0; i < m_values.Length; i++) { decimal item = m_values[i]; Color itc = Color.Black; Color ite = new Color(); if (m_pieColor.Length - 1 < i) { itc = ColorClass.GetColor(m_pieColor[i % (m_pieColor.Length - 1)], -20, 20, 6, 30); } else { itc = m_pieColor[i]; } if (item == 0) { if (sumValue == 0) { ite = Color.Gray; g.FillPie(new SolidBrush(ite), rec, startAngle, 360); g.DrawPie(new Pen(Color.FromArgb(224, 224, 224)), rec, startAngle, 360); sweepAngle = 0; } else { sweepAngle = 0; } } else { sweepAngle = (float)(360 / (sumValue / item)); } g.FillPie(new SolidBrush(itc), rec, startAngle, sweepAngle); g.DrawPie(new Pen(Color.FromArgb(224, 224, 224)), rec, startAngle, sweepAngle); //画底部 if (startAngle < 180) { float endang = startAngle + sweepAngle > 180 ? 180 : startAngle + sweepAngle; GraphicsPath gpath = GetGraphicPath.CreatePathForCylinderSurfaceSection(rec, startAngle, endang, startP, endP, m_height3D); g.FillPath(new SolidBrush(ColorClass.GetColor(sumValue == 0 ? ite : itc, 0, -80, -80, -80)), gpath); } if (m_bool) { if ((i * 20 + 9 + scroll) > 0 && (i * 20 + 9 + scroll) < this.Height - 40) { //画明细 Rectangle rectmx = new Rectangle(Padding.Left + PieWidth + 15, (i + 1) * 20 + 3 + scroll, 11, 11); g.FillRectangle(new SolidBrush(itc), rectmx); Rectangle textRect = new Rectangle(rectmx.X + rectmx.Width + 3, (i + 1) * 20 + 3 + scroll, 100, 14); Rectangle valueRect = new Rectangle(rectmx.X + rectmx.Width + 3 + 20, (i + 1) * 20 + 3 + scroll, 100, 14); Rectangle PMRect = new Rectangle(rectmx.X + rectmx.Width + 3 + 130, (i + 1) * 20 + 3 + scroll, 100, 14); StringFormat sformat = new StringFormat(); sformat.LineAlignment = StringAlignment.Center; string tiptext = ""; string bfbtext = ""; string pmtext = ""; if (m_text == null) { tiptext = ""; bfbtext = sumValue == 0 ? "0.00%" : (m_values[i] / sumValue).ToString("p"); pmtext = "TOP" + (i + 1); } else if (i >= m_text.Length) { tiptext = ""; bfbtext = sumValue == 0 ? "0.00%" : (m_values[i] / sumValue).ToString("p"); pmtext = "TOP" + (i + 1); } else { string st = m_text[i].Length > 5 ? m_text[i].Substring(0, 4).ToString() + "..." : m_text[i]; tiptext = st; bfbtext = sumValue == 0 ? "0.00%" : (m_values[i] / sumValue).ToString("p"); pmtext = "TOP" + (i + 1); } g.DrawString(tiptext, this.Font, new SolidBrush(ForeColor), textRect, sformat); sformat.Alignment = StringAlignment.Far; g.DrawString(bfbtext, this.Font, new SolidBrush(ForeColor), valueRect, sformat); sformat.Alignment = StringAlignment.Near; g.DrawString(pmtext, this.Font, new SolidBrush(ForeColor), PMRect, sformat); //g.DrawString(tiptext, Font, new SolidBrush(ForeColor), new PointF(rectmx.X + rectmx.Width + 3, (i + 1) * 20 + 3 + scroll)); } else { CanMoveScroll += 20; } } startAngle += sweepAngle; allRadius[i] = startAngle; //if (CanMoveScroll > 0 && -scroll < CanMoveScroll) //{ // jmButtonTriangle2.Visible = true; //} //else //{ // jmButtonTriangle2.Visible = false; //} } if (m_bool) { if ((m_values.Length > 10 && clickshu == 0) || (m_values.Length > 10 && clickshu < m_values.Length - 10)) { jmButtonTriangle2.Visible = true; } else { jmButtonTriangle2.Visible = false; } } //底部3D //GraphicsPath gpath = GetGraphicPath.CreatePathForCylinderSurfaceSection(rec, 120, 180, startP, endP, m_height3D); //g.FillPath(new SolidBrush(Color.FromArgb(100, 100, 100)), gpath); //g.FillRectangle(Brushes.Blue, recs); } Rectangle recs = new Rectangle(40, PieHeight + Padding.Top, 100, 50); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center;; g.DrawString(Text, this.Font, new SolidBrush(Color.Black), recs, sf); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); base.OnPaintBackground(e); Rectangle rectangle; //图片范围 Rectangle rectangle2; //字体范围 this.CalculateRect(out rectangle, out rectangle2); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; if (base.Enabled) { //填充按钮颜色效果 GraphicsPath aa = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); aa.CloseFigure(); //加载鼠标进入效果 if (SFVisibleEffect) { Color col1 = ColorClass.GetColor(_JMBaseColorTwo, 0, -20, -20, -20); Color col2 = ColorClass.GetColor(_JMBaseColor, 0, -20, -20, -20); GraphicsPath bb = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); bb.CloseFigure(); g.FillPath(new LinearGradientBrush(base.ClientRectangle, col1, col2, LinearGradientMode.Vertical), bb); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } else if (SFDownEffect)//加载鼠标按下效果 || Focused { Color col1 = ColorClass.GetColor(_JMBaseColorTwo, 0, -35, -35, -35); Color col2 = ColorClass.GetColor(_JMBaseColor, 0, -35, -35, -35); GraphicsPath cc = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); cc.CloseFigure(); g.FillPath(new LinearGradientBrush(base.ClientRectangle, col1, col2, LinearGradientMode.Vertical), cc); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } else { g.FillPath(new LinearGradientBrush(base.ClientRectangle, _JMBaseColorTwo, _JMBaseColor, LinearGradientMode.Vertical), aa); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } //加载图片 if (base.Image != null) { g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImage(base.Image, rectangle); } } else//不可用为“灰色” { //填充按钮颜色效果 GraphicsPath aa = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); aa.CloseFigure(); g.FillPath(new LinearGradientBrush(base.ClientRectangle, SystemColors.ControlDark, SystemColors.ControlDark, LinearGradientMode.Vertical), aa); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } //加载文字 TextRenderer.DrawText(g, this.Text, this.Font, rectangle2, this.ForeColor, TextFormat.GetTextFormatFlags(this.TextAlign, this.RightToLeft == RightToLeft.Yes)); if (_JMSFNew) { e.Graphics.DrawImage(Properties.Resources._new, new Rectangle(Width - 12, Height / 2 - 5, 10, 10)); } }
/// <summary> /// 画圆角渐变矩形 /// </summary> /// <param name="g">画布</param> /// <param name="rect">矩形区域</param> /// <param name="baseColor">填充颜色</param> /// <param name="borderColor">外边框颜色</param> /// <param name="innerBorderColor">内边框颜色</param> /// <param name="style">圆角样式</param> /// <param name="roundWidth">圆角弧度</param> /// <param name="basePosition">渐变占用比率(0.5为一半)</param> /// <param name="drawBorder">是否画边框</param> /// <param name="drawGlass">是否画高亮区域</param> /// <param name="GlassLight">高亮亮度</param> /// <param name="mode">渐变方向</param> internal static void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, int GlassLight, LinearGradientMode mode) { if (drawBorder) { rect.Width--; rect.Height--; } using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; colors[0] = ColorClass.GetColor(baseColor, 0, 35, 24, 9); colors[1] = ColorClass.GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = ColorClass.GetColor(baseColor, 0, 35, 24, 9); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GetGraphicPath.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GetGraphicPath.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } DrawGlass(g, glassRect, GlassLight, 0); } if (drawBorder) { using (GraphicsPath path = GetGraphicPath.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GetGraphicPath.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } if (drawGlass) { RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } DrawGlass(g, glassRect, GlassLight, 0); } if (drawBorder) { using (Pen pen = new Pen(borderColor)) { g.DrawRectangle(pen, rect); } rect.Inflate(-1, -1); using (Pen pen = new Pen(innerBorderColor)) { g.DrawRectangle(pen, rect); } } } } }