protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == 0x000F || m.Msg == 0x133) { IntPtr hDC = GetWindowDC(m.HWnd); if (hDC.ToInt32() == 0) { return; } Graphics graphics = Graphics.FromHdc(hDC); graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.Clear(Parent.BackColor); GraphicsPath backPath = RoundRectangle.CreateRoundRect(1, 1, Width - 2, Height - 2, 2); graphics.FillPath(new SolidBrush(Color.White), backPath); graphics.DrawPath(new(HopeColors.OneLevelBorder, 2), backPath); graphics.FillRectangle(new SolidBrush(Color.White), new RectangleF(1, 1, Width - 2, Height - 2)); graphics.DrawString(Text, Font, new SolidBrush(HopeColors.PrimaryColor), new Point(6, 6)); graphics.DrawString("6", new Font("Marlett", 12), new SolidBrush(SystemColors.ControlDark), new Rectangle(Width - 22, (Height - 18) / 2, 18, 18)); _ = ReleaseDC(m.HWnd, hDC); } }
/// <summary> /// 绘制背景和边框等 /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-08-01 16:47. private void DrawBackGround(Graphics g) { GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(1, 1, this.Width - 3, this.Height - 3); RoundRectangle roundRect = new RoundRectangle(rect, new Model.CornerRadius(this._CornerRadius)); switch (this._ControlState) { case EnumControlState.Default: if (this.FlatStyle != FlatStyle.Flat) { GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.DefaultControlColor); GDIHelper.DrawPathBorder(g, roundRect); } break; case EnumControlState.HeightLight: GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor); GDIHelper.DrawPathBorder(g, roundRect); break; case EnumControlState.Focused: GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.FocusedControlColor); GDIHelper.DrawPathBorder(g, roundRect); GDIHelper.DrawPathInnerBorder(g, roundRect); break; } }
/// <summary> /// 绘制指定区域路径的边框 /// </summary> public static void DrawPathOuterBorder(Graphics g, RoundRectangle roundRect, Color color, int borderWidth) { Rectangle rect = roundRect.Rect; rect.X--; rect.Y--; rect.Width += 2; rect.Height += 2; DrawPathBorder(g, new RoundRectangle(rect, roundRect.CornerRadius), color, borderWidth); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int w = this.BorderWidth > 0 ? this.BorderWidth : 0; Graphics g = e.Graphics; //缓冲 //BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; //BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle); //Graphics g = myBuffer.Graphics; GDIHelper.InitializeGraphics(g); GradientColor color = new GradientColor(this._BackBeginColor, this._BackEndColor, null, null); Rectangle rect = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius)); GDIHelper.FillRectangle(g, roundRect, color); if (this._BorderWidth > 0) { rect.X += this._BorderWidth - 1; rect.Y += this._BorderWidth - 1; rect.Width -= this._BorderWidth - 1; rect.Height -= this._BorderWidth - 1; GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, new CornerRadius(this._CornerRadius)), this._BorderColor, this.BorderWidth); // 上容器的边框 Rectangle rectPanel1 = new Rectangle(0, 0, this.Panel1.Width - 1, this.Panel1.Height - 1); GDIHelper.DrawPathBorder(g, new RoundRectangle(rectPanel1, new CornerRadius(0)), this._BorderColor, this.BorderWidth); } //g.SmoothingMode = SmoothingMode.HighQuality; //g.PixelOffsetMode = PixelOffsetMode.HighSpeed; //myBuffer.Render(e.Graphics); //g.Dispose(); //myBuffer.Dispose();//释放资源 }
/// <summary> /// 绘制指定区域路径的边框 /// </summary> public static void DrawPathInnerBorder(Graphics g, RoundRectangle roundRect) { Color c = SkinManager.CurrentSkin.InnerBorderColor; ////c = Color.Green; DrawPathInnerBorder(g, roundRect, c); }
/// <summary> /// 绘制指定区域路径的边框 /// </summary> public static void DrawPathInnerBorder(Graphics g, RoundRectangle roundRect, Color color) { Rectangle rect = roundRect.Rect; rect.X++; rect.Y++; rect.Width -= 2; rect.Height -= 2; DrawPathBorder(g, new RoundRectangle(rect, roundRect.CornerRadius), color); }
internal void RenderButton( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color arrowColor, ArrowDirection direction) { CornerRadius cr = new CornerRadius(); switch (direction) { case ArrowDirection.Left: cr = new CornerRadius(2, 0, 2, 0); break; case ArrowDirection.Right: cr = new CornerRadius(0, 2, 0, 2); break; } RoundRectangle roundRect = new RoundRectangle(rect, cr); GDIHelper.FillPath(g, roundRect, baseColor, baseColor); GDIHelper.DrawPathBorder(g, roundRect); using (SolidBrush brush = new SolidBrush(arrowColor)) { RenderArrowInternal( g, rect, direction, brush); } }
void AgregarPrivilegios() { RoundRectangle rr = new RoundRectangle(); Paragraph p = new Paragraph(); p.IndentationLeft = 8; List <PrivilegioReporte> privilegios = this.Privilegios.FindAll(x => x.Posicion == 3); PdfPTable tablaDatos = new PdfPTable(privilegios.Count > 4 ? 4 : privilegios.Count) { HorizontalAlignment = Element.ALIGN_LEFT }; tablaDatos.SpacingBefore = 10; tablaDatos.WidthPercentage = privilegios.Count > 4 ? 60 : privilegios.Count * 15; PdfPCell celda1; foreach (PrivilegioReporte item in privilegios) { celda1 = new PdfPCell(new Phrase(item.Descripcion, FontFactory.GetFont("VERDANA", 11, iTextSharp.text.Font.BOLD, BaseColor.BLACK))) { HorizontalAlignment = 1, CellEvent = rr, Border = PdfPCell.NO_BORDER, PaddingBottom = 6, PaddingTop = 6 }; tablaDatos.AddCell(celda1); } if (privilegios.Count > 4) { for (int i = 0; i < 8 - privilegios.Count; i++) { celda1 = new PdfPCell(new Phrase("")) { Border = 0 }; tablaDatos.AddCell(celda1); } } p.Add(tablaDatos); doc.Add(p); List <PrivilegioReporte> accesos = this.Privilegios.FindAll(x => x.Posicion == 4); PdfPTable tablaDatosAccesos = new PdfPTable(accesos.Count); tablaDatosAccesos.SpacingBefore = 20; tablaDatosAccesos.WidthPercentage = accesos.Count > 5 ? 90 : accesos.Count * 18; foreach (PrivilegioReporte item in accesos) { celda1 = new PdfPCell(new Phrase(item.Descripcion, FontFactory.GetFont("VERDANA", 16, iTextSharp.text.Font.BOLD, BaseColor.BLACK))) { HorizontalAlignment = 1, Padding = 4 }; tablaDatosAccesos.AddCell(celda1); } doc.Add(tablaDatosAccesos); float espacioTabla1 = tablaDatos.TotalHeight; float espacioTabla2 = tablaDatos.TotalHeight; AgregarCodigo(espacioTabla1 + espacioTabla2); }
/// <summary> /// 绘制指定区域路径的边框. /// 注意:若要设置边框宽度,需要自己调整区域,它是向外绘制的 /// </summary> /// <param name="g">The Graphics.</param> /// <param name="roundRect">The RoundRectangle.</param> /// <param name="color">The color.</param> /// <param name="borderWidth">Width of the border.</param> /// User:Ryan CreateTime:2011-07-28 16:11. public static void DrawPathBorder(Graphics g, RoundRectangle roundRect, Color color, int borderWidth) { using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (Pen pen = new Pen(color, borderWidth)) { g.DrawPath(pen, path); } } }
/// <summary> /// 绘制按钮 /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-08-02 14:23. private void DrawButton(Graphics g) { GDIHelper.InitializeGraphics(g); RoundRectangle btnRoundRect = new RoundRectangle(this.ButtonRect, 0); Color c = this.Enabled ? this._BackColor : SystemColors.Control; Size btnSize = new Size(20, 20); GDIHelper.FillRectangle(g, btnRoundRect, c); GDIHelper.DrawImage(g, this.ButtonRect, Properties.Resources.calendar, btnSize); }
private void DrawBackGround(Graphics g) { if (this.Width <= 3 || this.Height <= 3) { return; } Rectangle rect = new Rectangle(1, 1, this.Width - 3, this.Height - 3); RoundRectangle roundRect = new RoundRectangle(rect, this._cornerRadius); switch (this._state) { case ControlState.Default: if (this.FlatStyle != FlatStyle.Flat) { using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (LinearGradientBrush brush = new LinearGradientBrush(roundRect.Rect, Color.Yellow, Color.Blue, LinearGradientMode.Vertical)) { g.FillPath(brush, path); } using (Pen pen = new Pen(Color.Red, 1)) { g.DrawPath(pen, path); } } } break; case ControlState.HeightLight: using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (LinearGradientBrush brush = new LinearGradientBrush(roundRect.Rect, Color.Aqua, Color.Aquamarine, LinearGradientMode.Vertical)) { g.FillPath(brush, path); } using (Pen pen = new Pen(Color.Red, 1)) { g.DrawPath(pen, path); } } break; case ControlState.Focused: using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (LinearGradientBrush brush = new LinearGradientBrush(roundRect.Rect, Color.Beige, Color.BlanchedAlmond, LinearGradientMode.Vertical)) { g.FillPath(brush, path); } using (Pen pen = new Pen(Color.Red, 1)) { g.DrawPath(pen, path); } } var innerRoundRect = new RoundRectangle(new Rectangle(roundRect.Rect.X + 1, roundRect.Rect.Y + 1, roundRect.Rect.Width - 2, roundRect.Rect.Height - 2), roundRect.CornerRadius); using (GraphicsPath path = innerRoundRect.ToGraphicsBezierPath()) { using (Pen pen = new Pen(Color.Red, 1)) { g.DrawPath(pen, path); } } break; } }
public void TestRoundRectangleConstructor(string value) { RoundRectangle roundRectangle = _strokeShapeTypeConverter.ConvertFromInvariantString(value) as RoundRectangle; Assert.IsNotNull(roundRectangle); Assert.AreNotEqual(roundRectangle.CornerRadius.TopLeft, 0); Assert.AreNotEqual(roundRectangle.CornerRadius.TopRight, 0); Assert.AreNotEqual(roundRectangle.CornerRadius.BottomLeft, 0); Assert.AreNotEqual(roundRectangle.CornerRadius.BottomRight, 0); }
private void ResetRegion() { if (this._CornerRadius > 0) { Rectangle rect = new Rectangle(Point.Empty, this.Size); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius)); if (this.Region != null) { this.Region.Dispose(); } this.Region = new Region(roundRect.ToGraphicsBezierPath()); } }
/// <summary> /// 绘制默认边框 /// </summary> /// User:K.Anding CreateTime:2011-7-30 22:30. private void DrawDefaultBorder(Graphics g, Rectangle textRect) { Rectangle rect = new Rectangle(); rect.X = 0; rect.Y = textRect.Height / 2; rect.Height = this.Height - textRect.Height / 2 - 1; rect.Width = this.Width - 1; RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius)); g.SetClip(textRect, CombineMode.Exclude); GDIHelper.DrawPathBorder(g, roundRect, this._BorderColor, this._BorderWidth); g.ResetClip(); }
/// <summary> /// 创建ToolStrip的工作区域 /// </summary> /// <param name="toolStrip">The ToolStrip.</param> /// <param name="roundRect">The RoundRectangle.</param> /// User:Ryan CreateTime:2011-07-25 18:40. internal void CreateToolStripRegion(ToolStrip toolStrip, RoundRectangle roundRect) { using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { Region region = new Region(path); path.Widen(new Pen(this.MenuBorderColor)); region.Union(path); if (toolStrip.Region != null) { toolStrip.Region.Dispose(); } toolStrip.Region = region; } }
/// <summary> /// 使用渐变色填充区域 /// </summary> /// <param name="g">The g.</param> /// <param name="roundRect">The round rect.</param> /// <param name="color1">The color1.</param> /// <param name="color2">The color2.</param> /// User:Ryan CreateTime:2012-8-4 19:15. public static void FillPath(Graphics g, RoundRectangle roundRect, Color color1, Color color2) { if (roundRect.Rect.Width <= 0 || roundRect.Rect.Height <= 0) { return; } using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (LinearGradientBrush brush = new LinearGradientBrush(roundRect.Rect, color1, color2, LinearGradientMode.Vertical)) { g.FillPath(brush, path); } } }
/// <summary> /// 渲染一个圆角矩形区域(单色) /// Fills the rectangle. /// </summary> /// <param name="g">The g.</param> /// <param name="roundRect">The round rect.</param> /// <param name="color">The color.</param> /// User:Ryan CreateTime:2012-8-3 21:45. public static void FillRectangle(Graphics g, RoundRectangle roundRect, Color color) { if (roundRect.Rect.Width <= 0 || roundRect.Rect.Height <= 0) { return; } using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (Brush brush = new SolidBrush(color)) { g.FillPath(brush, path); } } }
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e) { ToolStripItem item = e.Item; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(0, 0, item.Width - 1, item.Height - 1); RoundRectangle roundRect = new RoundRectangle(rect, this.ItemCornerRadius); if (item.Selected || item.Pressed) { GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor); GDIHelper.DrawPathBorder(g, roundRect); } }
/// <summary> /// 绘制下拉框区域. /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-07-29 15:44. private void DrawComboBox(Graphics g) { GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(Point.Empty, this.Size); rect.Width--; rect.Height--; ////背景 RoundRectangle roundRect = new RoundRectangle(rect, 0); Color backColor = this.Enabled ? this._BackColor : SystemColors.Control; g.SetClip(this.EditRect, CombineMode.Exclude); GDIHelper.FillRectangle(g, roundRect, backColor); g.ResetClip(); this.DrawButton(g); GDIHelper.DrawPathBorder(g, roundRect); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); Bitmap B = new Bitmap(Width, Height); Graphics G = Graphics.FromImage(B); Rectangle ClientRectangle = new Rectangle(0, 0, Width, Height); Color TransparencyKey = this.ParentForm.TransparencyKey; LinearGradientBrush bBackground = new LinearGradientBrush(ClientRectangle, _Color1, _Color2, _ColorAngle); G.SmoothingMode = SmoothingMode.HighSpeed; G.Clear(TransparencyKey); // Draw the container borders G.FillPath(bBackground, RoundRectangle.RoundRect(ClientRectangle, BorderCurve)); // Draw a rectangle in which the controls should be added on G.FillPath(bBackground, RoundRectangle.RoundRect(new Rectangle(2, 20, Width - 5, Height - 42), BorderCurve)); // Patch the header with a rectangle that has a curve so its border will remain within container bounds G.FillPath(bBackground, RoundRectangle.RoundRect(new Rectangle(2, 2, (int)(Width / 2 + 2), 16), BorderCurve)); G.FillPath(bBackground, RoundRectangle.RoundRect(new Rectangle((int)(Width / 2 - 3), 2, (int)(Width / 2), 16), BorderCurve)); // Fill the header rectangle below the patch G.FillRectangle(bBackground, new Rectangle(2, 15, Width - 5, 10)); // Increase the thickness of the container borders G.DrawPath(new Pen(_BorderColor), RoundRectangle.RoundRect(new Rectangle(2, 2, Width - 5, Height - 5), BorderCurve)); G.DrawPath(new Pen(_BorderColor), RoundRectangle.RoundRect(ClientRectangle, BorderCurve)); // Draw the string from the specified 'Text' property on the header rectangle G.DrawString(Text, new Font("Trebuchet MS", 10, FontStyle.Bold), new SolidBrush(Color.FromArgb(221, 221, 221)), new Rectangle(BorderCurve, BorderCurve - 4, Width - 1, 22), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near }); // Draws a rectangle at the bottom of the container G.FillRectangle(bBackground, 0, Height - 25, Width - 3, 22 - 2); G.DrawLine(new Pen(_BorderColor), 5, Height - 5, Width - 6, Height - 5); G.DrawLine(new Pen(_BorderColor), 7, Height - 4, Width - 7, Height - 4); G.DrawString(_TextBottom, new Font("Trebuchet MS", 10, FontStyle.Bold), new SolidBrush(Color.FromArgb(221, 221, 221)), 5, Height - 23); e.Graphics.DrawImage((Image)(B.Clone()), 0, 0); G.Dispose(); B.Dispose(); }
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { ToolStripItem item = e.Item; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(2, -1, item.Width - 4, item.Height + 1); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(0)); if (item.Selected || item.Pressed) { Color c1 = Color.FromArgb(200, SkinManager.CurrentSkin.HeightLightControlColor.First); Color c2 = Color.FromArgb(250, c1); GDIHelper.FillRectangle(g, rect, SkinManager.CurrentSkin.HeightLightControlColor); //GDIHelper.DrawPathBorder(g, roundRect); } }
/// <summary> /// 渲染一个圆角矩形区域(渐变色) /// Fills the rectangle. /// </summary> /// <param name="g">The g.</param> /// <param name="roundRect">The round rect.</param> /// <param name="color">The color.</param> /// User:Ryan CreateTime:2012-8-3 21:45. public static void FillRectangle(Graphics g, RoundRectangle roundRect, GradientColor color) { if (roundRect.Rect.Width <= 0 || roundRect.Rect.Height <= 0) { return; } using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (LinearGradientBrush brush = new LinearGradientBrush(roundRect.Rect, color.First, color.Second, LinearGradientMode.Vertical)) { brush.Blend.Factors = color.Factors; brush.Blend.Positions = color.Positions; g.FillPath(brush, path); } } }
/// <summary> /// 绘制复选框和内容. /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-07-29 15:44. private void DrawContent(Graphics g) { GDIHelper.InitializeGraphics(g); int w = this.Width; int h = this.Height; Rectangle boxRect = new Rectangle(this._Margin, h / 2 - this._BoxSize.Height / 2, this._BoxSize.Width, this._BoxSize.Height); Size textSize = g.MeasureString(this.Text, this.Font).ToSize(); Rectangle textRect = new Rectangle(); textRect.X = boxRect.Right + this._Margin; textRect.Y = this._Margin; textRect.Height = this.Height - this._Margin * 2; textRect.Width = textSize.Width; RoundRectangle roundRect = new RoundRectangle(boxRect, this._CornerRadius); switch (this._ControlState) { case EnumControlState.HeightLight: //GDIHelper.DrawPathOuterBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor); GDIHelper.DrawPathBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor); GDIHelper.DrawPathInnerBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.First); break; default: GDIHelper.DrawCheckBox(g, roundRect); break; } Color c = base.Enabled ? this.ForeColor : SkinManager.CurrentSkin.UselessColor; //TextRenderer.DrawText(g, this.Text, this.Font, textRect, c, TextFormatFlags.Default); GDIHelper.DrawImageAndString(g, textRect, null, Size.Empty, this.Text, this.Font, c); switch (this.CheckState) { case System.Windows.Forms.CheckState.Checked: GDIHelper.DrawCheckedStateByImage(g, boxRect); break; case System.Windows.Forms.CheckState.Indeterminate: Rectangle innerRect = boxRect; innerRect.Inflate(-3, -3); Color cc = Color.FromArgb(46, 117, 35); GDIHelper.FillRectangle(g, new RoundRectangle(innerRect, this._CornerRadius), cc); break; } }
/// <summary> /// 绘制checkbox的边框和背景 /// </summary> /// User:Ryan CreateTime:2011-07-25 18:00. public static void DrawCheckBox(Graphics g, RoundRectangle roundRect) { using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (PathGradientBrush brush = new PathGradientBrush(path)) { brush.CenterColor = SkinManager.CurrentSkin.BaseColor; brush.SurroundColors = new Color[] { SkinManager.CurrentSkin.BorderColor }; Blend blend = new Blend(); blend.Positions = new float[] { 0f, 0.18f, 1f }; blend.Factors = new float[] { 0f, 0.89f, 1f }; brush.Blend = blend; g.FillPath(brush, path); } DrawPathBorder(g, roundRect); } }
private void DrawBorder(Graphics g) { GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(1, 1, this.Width - 3, this.Height - 3); RoundRectangle roundRect = new RoundRectangle(rect, this._CornerRadius); Color c = (!this._TextBox.Enabled || this._TextBox.ReadOnly) ? Color.FromArgb(215, 250, 243) : Color.White; this._TextBox.BackColor = c; //this._TextBox.Font = this._Font; //this._TextBox.ForeColor = this._ForeColor; GDIHelper.FillPath(g, roundRect, c, c); GDIHelper.DrawPathBorder(g, roundRect, this._BorderColor); if (this._ControlState == EnumControlState.HeightLight) { GDIHelper.DrawPathBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.Second); GDIHelper.DrawPathOuterBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.First); } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { ToolStripItem item = e.Item; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); ////你真没救了!好吧,我承认我是个具有文艺气质的2B程序员 if (item.Tag != null && item.Tag.Equals("Vicky")) { int temp = item.Width >= item.Height ? item.Height : item.Width; Rectangle rect = new Rectangle(0, 0, temp, temp); rect.Inflate(-1, -1); Color c1 = Color.Empty, c2 = Color.Empty, c3 = Color.FromArgb(255, 220, 102); Blend blend = new Blend(); blend.Positions = new float[] { 0f, 0.5f, 1f }; blend.Factors = new float[] { 0.25f, 0.75f, 1f }; Color borderColor = item.Selected || item.Pressed ? Color.FromArgb(24, 116, 205) : SkinManager.CurrentSkin.BorderColor; float w = 1.0F; g.PixelOffsetMode = PixelOffsetMode.HighQuality; if (item.Selected || item.Pressed) { w = 2.0F; c1 = Color.FromArgb(255, 226, 48); c2 = Color.FromArgb(255, 220, 102); GDIHelper.DrawCrystalButton(g, rect, c1, c2, c3, blend); } using (Pen p = new Pen(borderColor, w)) { g.DrawEllipse(p, rect); } } else { Rectangle rect = new Rectangle(1, 1, item.Width - 4, item.Height - 3); RoundRectangle roundRect = new RoundRectangle(rect, this.ItemCornerRadius); if (item.Selected || item.Pressed) { GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor); GDIHelper.DrawPathBorder(g, roundRect); } } }
/// <summary> /// 绘制按钮 /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-08-02 14:23. private void DrawButton(Graphics g) { Rectangle btnRect; EnumControlState btnState = this.GetComboBoxButtonPressed() ? EnumControlState.HeightLight : EnumControlState.Default; btnRect = new Rectangle(this.ButtonRect.X, this.ButtonRect.Y - 1, this.ButtonRect.Width + 1 + this._Margin, this.ButtonRect.Height + 2); RoundRectangle btnRoundRect = new RoundRectangle(btnRect, new CornerRadius(0)); //Blend blend = new Blend(3); //blend.Positions = new float[] { 0f, 0.5f, 1f }; //blend.Factors = new float[] { 0f, 1f, 0f }; GDIHelper.FillRectangle(g, btnRoundRect, SkinManager.CurrentSkin.DefaultControlColor); Size btnSize = new Size(12, 7); GDIHelper.DrawArrow(g, ArrowDirection.Down, btnRect, btnSize, 0f, Color.FromArgb(30, 178, 239)); Color lineColor = SkinManager.CurrentSkin.BorderColor; GDIHelper.DrawGradientLine(g, lineColor, 90, btnRect.X, btnRect.Y, btnRect.X, btnRect.Bottom - 1); }
/// <summary> /// 绘制窗体边框 /// </summary> /// <param name="g">The g.</param> /// User:Ryan CreateTime:2012-8-3 22:22. public void DrawFormBorder(Graphics g) { if (this.WindowState == FormWindowState.Maximized) { return; } Rectangle rect = new Rectangle(0, 0, this.Width - 2, this.Height - 2); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this.CornerRadius)); //GDIHelper.DrawPathBorder(g, roundRect); using (GraphicsPath path = this._CornerRadius == 0 ? roundRect.ToGraphicsBezierPath() : roundRect.ToGraphicsArcPath()) { using (Pen pen = new Pen(SkinManager.CurrentSkin.BorderColor)) { g.DrawPath(pen, path); } } }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { e.ToolStrip.ForeColor = HopeColors.MainText; if (e.ToolStrip is ToolStripDropDown) { Graphics g = e.Graphics; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.Clear(Color.White); GraphicsPath bg = RoundRectangle.CreateRoundRect(0.5f, 0.5f, e.AffectedBounds.Width - 1, e.AffectedBounds.Height - 1, 3); g.DrawPath(new(HopeColors.OneLevelBorder, 1), bg); g.FillPath(new SolidBrush(Color.White), bg); } else { base.OnRenderToolStripBackground(e); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int w = this.BorderWidth > 0 ? this.BorderWidth : 0; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); GradientColor color = new GradientColor(this._BackBeginColor, this._BackEndColor, null, null); Rectangle rect = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius)); GDIHelper.FillRectangle(g, roundRect, color); if (this._BorderWidth > 0) { rect.X += this._BorderWidth - 1; rect.Y += this._BorderWidth - 1; rect.Width -= this._BorderWidth - 1; rect.Height -= this._BorderWidth - 1; GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, new CornerRadius(this._CornerRadius)), this._BorderColor, this.BorderWidth); } }