protected override void OnPaintBackground(PaintEventArgs e) { if ((base.BackColor == Color.Transparent && base.BackgroundImage == null) || _roundStyle == RoundStyle.None) { base.OnPaintBackground(e); } else { Graphics g = e.Graphics; using (GraphicsPath path = GraphicsPathHelper.CreatePath( base.ClientRectangle, _radius, _roundStyle, true)) { GraphicsState gState = g.Save(); g.SetClip(path); base.OnPaintBackground(e); g.Restore(gState); g.ExcludeClip(new Region(path)); ButtonRenderer.DrawParentBackground( g, base.ClientRectangle, this); g.ResetClip(); } } }
private void DrawSaturationTrack( Graphics g, Rectangle rect, bool horizontal) { float angle = horizontal ? 0f : 90f; using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, 6, RoundStyle.All, true)) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Empty, Color.Empty, angle)) { brush.InterpolationColors = _blend; g.FillPath(brush, path); } using (Pen pen = new Pen(_baseColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, 6, RoundStyle.All, true)) { using (Pen pen = new Pen(InnerBorderColor)) { g.DrawPath(pen, path); } } }
internal static void DrawGradientRoundRect(Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Blend blend, LinearGradientMode mode, int radios, RoundStyle roundStyle, bool drawBorder, bool drawInnderBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radios, roundStyle, true)) { using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, begin, end, mode)) { linearGradientBrush.Blend = blend; g.FillPath((Brush)linearGradientBrush, path); } if (drawBorder) { using (Pen pen = new Pen(border)) g.DrawPath(pen, path); } } if (!drawInnderBorder) { return; } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radios, roundStyle, true)) { using (Pen pen = new Pen(innerBorder)) g.DrawPath(pen, path); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; using (GraphicsPath path = GraphicsPathHelper.CreatePath( ClientRectangle, 8, RoundStyle.All, false)) { using (SolidBrush brush = new SolidBrush(ColorTable.BackColorNormal)) { g.FillPath(brush, path); } using (Pen pen = new Pen(ColorTable.BorderColor)) { g.DrawPath(pen, path); using (GraphicsPath innerPath = GraphicsPathHelper.CreatePath( ClientRectangle, 8, RoundStyle.All, true)) { g.DrawPath(pen, innerPath); } } } }
private void RenderBorder(Graphics g, Rectangle bounds) { if (ShowBorder == false) { return; } if (RoundStyle == RoundStyle.None) { ControlPaint.DrawBorder( g, bounds, ColorTable.Border, ButtonBorderStyle.Solid); } else { using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, Radius, RoundStyle, true)) { using (Pen pen = new Pen(ColorTable.Border)) { g.DrawPath(pen, path); } } } } }
private void DrawOpacityTrack( Graphics g, Rectangle rect, bool horizontal) { float mode = horizontal ? 0f : 270f; using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, 6, RoundStyle.All, true)) { g.FillPath(Brushes.White, path); using (Pen pen = new Pen(_baseColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); List <Point> points = GetOpacityBackLinePoints(rect, 3, horizontal); g.DrawLines(Pens.Silver, points.ToArray()); using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, 6, RoundStyle.All, true)) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, _baseColor, Color.Transparent, mode)) { g.FillPath(brush, path); } } }
protected virtual void RenderElapsedBar(PaintEventArgs e) { Color color1 = ElapsedBarSchema.BackNormalStyle.Color1; Color color2 = ElapsedBarSchema.BackNormalStyle.Color2; Color borderColor = ElapsedBarSchema.BorderNormalStyle.Color1; if (Enabled) { switch (ControlState) { case ControlState.Hover: case ControlState.Pressed: color1 = ElapsedBarSchema.BackHoverStyle.Color1; color2 = ElapsedBarSchema.BackHoverStyle.Color2; borderColor = ElapsedBarSchema.BorderHoverStyle.Color1; break; } } else { color1 = ElapsedBarSchema.BackDisabledStyle.Color1; color2 = ElapsedBarSchema.BackDisabledStyle.Color2; borderColor = ElapsedBarSchema.BorderDisabledStyle.Color1; } if (elapsedRect.Width > 0 && elapsedRect.Height > 0) { using ( LinearGradientBrush lgbElapsed = new LinearGradientBrush(elapsedRect, color1, color2, gradientOrientation)) { //lgbElapsed.WrapMode = WrapMode.TileFlipXY; if (Radius == 0) { e.Graphics.FillRectangle(lgbElapsed, elapsedRect); using (Pen p = new Pen(borderColor)) { e.Graphics.DrawRectangle(p, barRect); } } else { RoundStyle r = (Orientation == Orientation.Horizontal) ? RoundStyle.Left : RoundStyle.Bottom; //RoundStyle r = (Orientation == Orientation.Horizontal) ? RoundStyle.Left : RoundStyle.Top; using (GraphicsPath path = GraphicsPathHelper.CreatePath(elapsedRect, Radius, r, false)) { e.Graphics.FillPath(lgbElapsed, path); using (Pen p = new Pen(borderColor)) { e.Graphics.DrawPath(p, path); } } } } } }
protected override void OnRenderImageMargin(ToolStripRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; Graphics graphics = e.Graphics; Rectangle affectedBounds = e.AffectedBounds; if (toolStrip is ToolStripDropDown) { bool flag = toolStrip.RightToLeft == RightToLeft.Yes; Rectangle rectangle2 = affectedBounds; Rectangle rect = affectedBounds; if (flag) { rect.X -= 2; rectangle2.X = rect.X; } else { rect.X += 2; rectangle2.X = rect.Right; } rect.Y++; rect.Height -= 2; using (LinearGradientBrush brush = new LinearGradientBrush(rect, this.ColorTable.TitleColor, this.ColorTable.Back, 90f)) { Blend blend = new Blend(); float[] numArray = new float[3]; numArray[1] = 0.2f; numArray[2] = 1f; blend.Positions = numArray; float[] numArray2 = new float[3]; numArray2[1] = 0.1f; numArray2[2] = 0.9f; blend.Factors = numArray2; brush.Blend = blend; rect.Y++; rect.Height -= 2; using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, this.ColorTable.TitleRadius, this.ColorTable.TitleRadiusStyle, false)) { using (new SmoothingModeGraphics(graphics)) { if (this.ColorTable.TitleAnamorphosis) { graphics.FillPath(brush, path); } else { SolidBrush brush2 = new SolidBrush(this.ColorTable.TitleColor); graphics.FillPath(brush2, path); } return; } } } } base.OnRenderImageMargin(e); }
public override Region CreateRegion(FormBase form) { Rectangle rect = new Rectangle(Point.Empty, form.Size); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, form.Radius, form.RoundStyle, false)) { return(new Region(path)); } }
private void DrowImage(Graphics g) { Rectangle rect = new Rectangle(0, 0, Image.Width, Image.Height); //GraphicsPath path = GraphicsPathHelper.DrawRoundRect(0,0, this.Width, this.Height,10); GraphicsPath path = GraphicsPathHelper.CreatePath(rect, 10, RoundStyle.All, true); g.SetClip(path); g.DrawImage(Image, 0, 0); //g.DrawImageUnscaledAndClipped(Image, rect); }
//圆角 private void SetReion() { using (GraphicsPath path = GraphicsPathHelper.CreatePath( new Rectangle(Point.Empty, base.Size), 6, RoundStyle.All, true)) { Region region = new Region(path); path.Widen(Pens.White); region.Union(path); this.Region = region; } }
protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics; Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radius, RoundStyle.All, true); g.SetClip(path); base.OnPaint(pe); }
public static void CreateRegion(Control control, Rectangle rect) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, 8, RoundStyle.All, false)) { if (control.Region != null) { control.Region.Dispose(); } control.Region = new Region(path); } }
private void SetReion() { if (base.Region != null) { base.Region.Dispose(); } using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, false)) { base.Region = new Region(path); } }
protected override void OnRenderToolStripBackground( ToolStripRenderEventArgs e) { Color baseColor = ColorTable.BackColorNormal; ToolStrip toolStrip = e.ToolStrip; Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; if (toolStrip is ToolStripDropDown) { RegionHelper.CreateRegion(e.ToolStrip, e.AffectedBounds); Rectangle rect = e.AffectedBounds; using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, 8, RoundStyle.All, false)) { using (SolidBrush brush = new SolidBrush(ColorTable.BackColorNormal)) { g.FillPath(brush, path); } using (Pen pen = new Pen(ColorTable.BorderColor)) { g.DrawPath(pen, path); using (GraphicsPath innerPath = GraphicsPathHelper.CreatePath( rect, 8, RoundStyle.All, true)) { g.DrawPath(pen, innerPath); } } } } else { LinearGradientMode mode = e.ToolStrip.Orientation == Orientation.Horizontal ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; RenderBackgroundInternal( g, e.AffectedBounds, ColorTable.BackColorHover, ColorTable.BorderColor, ColorTable.BackColorNormal, RoundStyle.All, false, true, mode); } }
protected override void OnPaint(PaintEventArgs e) { //测量文字大小 Size szFont = Text.Length != 0 ? TextRenderer.MeasureText(Text, this.Font) : TextRenderer.MeasureText("空", this.Font); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; //最高质量绘制文字 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; //画背景 g.FillRectangle(new SolidBrush(base.BackColor), this.ClientRectangle); //取得轮廓 using (GraphicsPath path = GraphicsPathHelper.CreatePath(new Rectangle(1, 1 + szFont.Height / 2, Width - 2, Height - 2 - szFont.Height / 2), Radius, RoundStyle, false)) { //画框内填充 using (SolidBrush br = new SolidBrush(RectBackColor)) { g.FillPath(br, path); } //画框内边框 using (Pen pen = new Pen(BorderColor)) { g.DrawPath(pen, path); } } //判断标题是否为空 if (Text.Length != 0) { //取得轮廓 using (GraphicsPath path = GraphicsPathHelper.CreatePath(new Rectangle(new Point(7, 1), new Size(szFont.Width, szFont.Height)), TitleRadius, TitleRoundStyle, false)) { //画字框内填充 using (SolidBrush br = new SolidBrush(TitleRectBackColor)) { g.FillPath(br, path); } //画字框内边框 using (Pen pen = new Pen(TitleBorderColor)) { g.DrawPath(pen, path); } } //画字 e.Graphics.DrawString(Text, this.Font, new SolidBrush(this.ForeColor), new Point(7, 1)); } }
protected override void OnPaint(PaintEventArgs pe) { Graphics g = pe.Graphics; Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); GraphicsPath path = GraphicsPathHelper.CreatePath(rect, 10, RoundStyle.All, true); g.SetClip(path); //if (Image != null) //{ // DrowImage(g); //} base.OnPaint(pe); }
internal void RenderBorder(Graphics g, Rectangle bounds) { switch (_captionStyle) { case CaptionStyle.Top: case CaptionStyle.Bottom: if (base.Height <= _captionHeight) { return; } break; case CaptionStyle.Left: case CaptionStyle.Right: if (base.Width <= _captionHeight) { return; } break; } if (_showBorder) { if (RoundStyle == RoundStyle.None) { ControlPaint.DrawBorder( g, bounds, ColorTable.Border, ButtonBorderStyle.Solid); } else { using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, Radius, RoundStyle, true)) { using (Pen pen = new Pen(ColorTable.Border)) { g.DrawPath(pen, path); } } } } } }
private void DrawBorder(Graphics g, Rectangle rect, RoundStyle roundStyle, int radius, FormBase frm) { g.SmoothingMode = SmoothingMode.HighQuality; rect.Width--; rect.Height--; using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radius, roundStyle, false)) { using (Pen pen = new Pen(this.ColorTable.Border)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(rect, radius, roundStyle, false)) { using (Pen pen2 = new Pen(this.ColorTable.InnerBorder)) { g.DrawPath(pen2, path2); } } }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; Graphics graphics = e.Graphics; Rectangle affectedBounds = e.AffectedBounds; if (toolStrip is ToolStripDropDown) { if (this.ColorTable.RadiusStyle == RoundStyle.None) { affectedBounds.Width--; affectedBounds.Height--; } using (new SmoothingModeGraphics(graphics)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(affectedBounds, this.ColorTable.BackRadius, this.ColorTable.RadiusStyle, true)) { using (Pen pen = new Pen(this.ColorTable.DropDownImageSeparator)) { path.Widen(pen); graphics.DrawPath(pen, path); } } } if (toolStrip is ToolStripOverflow) { return; } affectedBounds.Inflate(-1, -1); using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(affectedBounds, this.ColorTable.BackRadius, this.ColorTable.RadiusStyle, true)) { using (Pen pen2 = new Pen(this.ColorTable.Back)) { graphics.DrawPath(pen2, path2); } return; } } base.OnRenderToolStripBorder(e); }
protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; if (Radius == 0) { using (SolidBrush br = new SolidBrush(BackColor)) { e.Graphics.FillRectangle(br, ClientRectangle); } using (Pen p = new Pen(BorderColor)) { e.Graphics.DrawRectangle(p, new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1)); } } else { using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { using (SolidBrush br = new SolidBrush(BackColor)) { e.Graphics.FillPath(br, path); } using (Pen pen = new Pen(BorderColor)) { e.Graphics.DrawPath(pen, path); } } } if (ControlState == ControlState.Hover || ControlState == ControlState.Pressed) { using (SolidBrush br = new SolidBrush(_searchBtnHoverBackColor)) { e.Graphics.FillRectangle(br, SearchBtnRectangle); } } }
protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, false)) { if (controlSchema.BackNormalStyle.Color2 != Color.Empty && controlSchema.BackNormalStyle.Color1 != controlSchema.BackNormalStyle.Color2) { if (ClientRectangle.Width > 0 && ClientRectangle.Height > 0) { using (LinearGradientBrush br = new LinearGradientBrush(ClientRectangle, controlSchema.BackNormalStyle.Color1, controlSchema.BackNormalStyle.Color2, controlSchema.BackNormalStyle.Mode)) { g.FillPath(br, path); } } } else { using (SolidBrush br = new SolidBrush(controlSchema.BackNormalStyle.Color1)) { g.FillPath(br, path); } } } #region 画border Rectangle r = ClientRectangle; //r.Width -= 1; //r.Height -= 1; using (GraphicsPath path = GraphicsPathHelper.CreatePath(r, Radius, RoundStyle, true)) { using (Pen p = new Pen(controlSchema.BorderNormalStyle.Color1)) { g.DrawPath(p, path); } } if (controlSchema.BorderNormalStyle.Color2 != Color.Empty && controlSchema.BorderNormalStyle.Color2 != controlSchema.BorderNormalStyle.Color1) { r.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath( r, radius, roundStyle, true)) { using (Pen pen = new Pen(controlSchema.BorderNormalStyle.Color2)) { g.DrawPath(pen, path); } } } #endregion #region 画背景图片 if (BackgroundImage != null) { switch (BackgroundImageLayout) { case ImageLayout.None: g.DrawImageUnscaled(BackgroundImage, ClientRectangle.X, ClientRectangle.Y, BackgroundImage.Width, BackgroundImage.Height); break; case ImageLayout.Tile: using (TextureBrush Txbrus = new TextureBrush(BackgroundImage)) { Txbrus.WrapMode = WrapMode.Tile; g.FillRectangle(Txbrus, new Rectangle(0, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1)); } break; case ImageLayout.Center: int xx = (ClientRectangle.Width - BackgroundImage.Width) / 2; int yy = (ClientRectangle.Height - BackgroundImage.Height) / 2; g.DrawImage(BackgroundImage, new Rectangle(xx, yy, BackgroundImage.Width, BackgroundImage.Height), new Rectangle(0, 0, BackgroundImage.Width, BackgroundImage.Height), GraphicsUnit.Pixel); break; case ImageLayout.Stretch: g.DrawImage(BackgroundImage, new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height), new Rectangle(0, 0, BackgroundImage.Width, BackgroundImage.Height), GraphicsUnit.Pixel); break; case ImageLayout.Zoom: { double tm = 0.0; int W = BackgroundImage.Width; int H = BackgroundImage.Height; if (W > ClientRectangle.Width) { tm = ClientRectangle.Width / BackgroundImage.Width; W = (int)(W * tm); H = (int)(H * tm); } if (H > ClientRectangle.Height) { tm = ClientRectangle.Height / H; W = (int)(W * tm); H = (int)(H * tm); } using (Bitmap tmpBP = new Bitmap(W, H)) { using (Graphics G2 = Graphics.FromImage(tmpBP)) { G2.DrawImage(BackgroundImage, new Rectangle(0, 0, W, H), new Rectangle(0, 0, BackgroundImage.Width, BackgroundImage.Height), GraphicsUnit.Pixel); int xxx = (ClientRectangle.Width - W) / 2; int yyy = (ClientRectangle.Height - H) / 2; g.DrawImage(tmpBP, new Rectangle(xxx, yyy, W, H), new Rectangle(0, 0, W, H), GraphicsUnit.Pixel); } } } break; } } #endregion }
private void RenderBackgroundInternal(Graphics g , Rectangle ClientRectangle , BrushParameter backStyle , BrushParameter bordStyle , Ants.Controls.RoundStyle RoundStyle , int Radius) { #region 画背景 if (backStyle.Color2 == Color.Empty || backStyle.Color2 == backStyle.Color1) { using (SolidBrush brush = new SolidBrush(backStyle.Color1)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { g.FillPath(brush, path); } } } else { using (LinearGradientBrush brush = new LinearGradientBrush( ClientRectangle, backStyle.Color1, backStyle.Color2, backStyle.Mode)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { g.FillPath(brush, path); } } } #endregion #region 画边框 using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { using (Pen pen = new Pen(bordStyle.Color1)) { g.DrawPath(pen, path); } } if (bordStyle.Color2 != Color.Empty) { ClientRectangle.Inflate(-1, -1); Rectangle r = ClientRectangle; r.X += 1; r.Y += 1; r.Width -= 2; r.Height -= 2; using (GraphicsPath path = //GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, false)) GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { using (Pen pen = new Pen(bordStyle.Color2)) { g.DrawPath(pen, path); } } } #endregion }
public void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, 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] = GetColor(baseColor, 0, 35, 24, 9); colors[1] = GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = 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; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (drawGlass) { 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 = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } 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, 170, 0); } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (drawGlass) { 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); } } 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, 200, 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); } } } } }
public static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode) { if (drawBorder) { rect.Width--; rect.Height--; } using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Color[] colorArray = new Color[] { GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor, GetColor(baseColor, 0, 0x23, 0x18, 9) }; ColorBlend blend = new ColorBlend(); float[] numArray = new float[4]; numArray[1] = basePosition; numArray[2] = basePosition + 0.05f; numArray[3] = 1f; blend.Positions = numArray; blend.Colors = colorArray; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (drawGlass) { if (baseColor.A > 80) { Rectangle rectangle = rect; if (mode == LinearGradientMode.Vertical) { rectangle.Height = (int)(rectangle.Height * basePosition); } else { rectangle.Width = (int)(rect.Width * basePosition); } using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(rectangle, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brush2 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff))) { g.FillPath(brush2, path2); } } } RectangleF glassRect = rect; if (mode == LinearGradientMode.Vertical) { glassRect.Y = rect.Y + (rect.Height * basePosition); glassRect.Height = (rect.Height - (rect.Height * basePosition)) * 2f; } else { glassRect.X = rect.X + (rect.Width * basePosition); glassRect.Width = (rect.Width - (rect.Width * basePosition)) * 2f; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); } if (!drawBorder) { return; } using (GraphicsPath path3 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path3); } } rect.Inflate(-1, -1); using (GraphicsPath path4 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen2 = new Pen(innerBorderColor)) { g.DrawPath(pen2, path4); } return; } } g.FillRectangle(brush, rect); if (drawGlass) { if (baseColor.A > 80) { Rectangle rectangle2 = rect; if (mode == LinearGradientMode.Vertical) { rectangle2.Height = (int)(rectangle2.Height * basePosition); } else { rectangle2.Width = (int)(rect.Width * basePosition); } using (SolidBrush brush3 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff))) { g.FillRectangle(brush3, rectangle2); } } RectangleF ef2 = rect; if (mode == LinearGradientMode.Vertical) { ef2.Y = rect.Y + (rect.Height * basePosition); ef2.Height = (rect.Height - (rect.Height * basePosition)) * 2f; } else { ef2.X = rect.X + (rect.Width * basePosition); ef2.Width = (rect.Width - (rect.Width * basePosition)) * 2f; } ControlPaintEx.DrawGlass(g, ef2, 200, 0); } if (drawBorder) { using (Pen pen3 = new Pen(borderColor)) { g.DrawRectangle(pen3, rect); } rect.Inflate(-1, -1); using (Pen pen4 = new Pen(innerBorderColor)) { g.DrawRectangle(pen4, rect); } } } }
internal static void RenderBackgroundInternal3( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode) { if (drawBorder) { rect.Width--; rect.Height--; } if (rect.Width < 1 || rect.Height < 1) { return; } using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { FillBrush(brush, baseColor, borderColor, basePosition, drawGlass); if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } 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; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); if (baseColor.A > 0) { Rectangle rectTop = rect; if (mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); 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; } ControlPaintEx.DrawGlass(g, glassRect, 200, 0); 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 (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); } } } } }
protected override void OnRenderToolStripBorder( ToolStripRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; Graphics g = e.Graphics; Rectangle bounds = e.AffectedBounds; if (toolStrip is ToolStripDropDown) { using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(bounds, 8, RoundStyle.All, true)) { using (Pen pen = new Pen(ColorTable.DropDownImageSeparator)) { path.Widen(pen); g.DrawPath(pen, path); } } } bounds.Inflate(-1, -1); using (GraphicsPath innerPath = GraphicsPathHelper.CreatePath( bounds, 8, RoundStyle.All, true)) { using (Pen pen = new Pen(ColorTable.BackNormal)) { g.DrawPath(pen, innerPath); } } } else if (toolStrip is StatusStrip) { using (Pen pen = new Pen(ColorTable.Border)) { e.Graphics.DrawRectangle( pen, 0, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1); } } else if (toolStrip is MenuStrip) { base.OnRenderToolStripBorder(e); } else { using (Pen pen = new Pen(ColorTable.Border)) { g.DrawRectangle( pen, 0, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1); } } }
protected override void OnRenderImageMargin( ToolStripRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; Graphics g = e.Graphics; Rectangle bounds = e.AffectedBounds; if (toolStrip is ToolStripDropDown) { bool bDrawLogo = NeedDrawLogo(toolStrip); bool bRightToLeft = toolStrip.RightToLeft == RightToLeft.Yes; Rectangle imageBackRect = bounds; imageBackRect.Width = OffsetMargin; if (bDrawLogo) { Rectangle logoRect = bounds; logoRect.Width = OffsetMargin; if (bRightToLeft) { logoRect.X -= 2; imageBackRect.X = logoRect.X - OffsetMargin; } else { logoRect.X += 2; imageBackRect.X = logoRect.Right; } logoRect.Y += 1; logoRect.Height -= 2; using (LinearGradientBrush brush = new LinearGradientBrush( logoRect, ColorTable.BackHover, ColorTable.BackNormal, 90f)) { Blend blend = new Blend(); blend.Positions = new float[] { 0f, .2f, 1f }; blend.Factors = new float[] { 0f, 0.1f, .9f }; brush.Blend = blend; logoRect.Y += 1; logoRect.Height -= 2; using (GraphicsPath path = GraphicsPathHelper.CreatePath(logoRect, 8, RoundStyle.All, false)) { using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g)) { g.FillPath(brush, path); } } } StringFormat sf = new StringFormat(StringFormatFlags.NoWrap); Font font = new Font( toolStrip.Font.FontFamily, 11, FontStyle.Bold); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; g.TranslateTransform(logoRect.X, logoRect.Bottom); g.RotateTransform(270f); if (!string.IsNullOrEmpty(MenuLogoString)) { Rectangle newRect = new Rectangle( 0, 0, logoRect.Height, logoRect.Width); using (Brush brush = new SolidBrush(ColorTable.Fore)) { using (TextRenderingHintGraphics tg = new TextRenderingHintGraphics(g)) { g.DrawString( MenuLogoString, font, brush, newRect, sf); } } } g.ResetTransform(); } else { if (bRightToLeft) { imageBackRect.X -= 3; } else { imageBackRect.X += 3; } } imageBackRect.Y += 2; imageBackRect.Height -= 4; using (SolidBrush brush = new SolidBrush(ColorTable.DropDownImageBack)) { g.FillRectangle(brush, imageBackRect); } Point ponitStart; Point pointEnd; if (bRightToLeft) { ponitStart = new Point(imageBackRect.X, imageBackRect.Y); pointEnd = new Point(imageBackRect.X, imageBackRect.Bottom); } else { ponitStart = new Point(imageBackRect.Right - 1, imageBackRect.Y); pointEnd = new Point(imageBackRect.Right - 1, imageBackRect.Bottom); } using (Pen pen = new Pen(ColorTable.DropDownImageSeparator)) { g.DrawLine(pen, ponitStart, pointEnd); } } else { base.OnRenderImageMargin(e); } }
/// <summary> /// 画bar条 /// </summary> /// <param name="e"></param> protected virtual void RenderBar(PaintEventArgs e) { Color color1 = BarFaceSchema.BackNormalStyle.Color1; Color color2 = BarFaceSchema.BackNormalStyle.Color2; Color borderColor = BarFaceSchema.BorderNormalStyle.Color1; if (Enabled) { switch (ControlState) { case ControlState.Hover: case ControlState.Pressed: color1 = BarFaceSchema.BackHoverStyle.Color1; color2 = BarFaceSchema.BackHoverStyle.Color2; borderColor = BarFaceSchema.BorderHoverStyle.Color1; break; } } else { color1 = BarFaceSchema.BackDisabledStyle.Color1; color2 = BarFaceSchema.BackDisabledStyle.Color2; borderColor = BarFaceSchema.BorderDisabledStyle.Color1; } if (barRect.Width > 0 && barRect.Height > 0) { //draw bar using ( LinearGradientBrush lgbBar = new LinearGradientBrush( barRect , color1 , color2 , gradientOrientation) ) { Rectangle r = new Rectangle(); //lgbBar.WrapMode = WrapMode.TileFlipXY; if (Radius == 0) { e.Graphics.FillRectangle(lgbBar, barRect); using (Pen p = new Pen(borderColor)) { e.Graphics.DrawRectangle(p, barRect); } } else { using (GraphicsPath path = GraphicsPathHelper.CreatePath(barRect, Radius, RoundStyle, false)) { e.Graphics.FillPath(lgbBar, path); using (Pen p = new Pen(borderColor)) { e.Graphics.DrawPath(p, path); } } } } } }
protected override void OnRenderImageMargin( ToolStripRenderEventArgs e) { if (e.ToolStrip is ToolStripDropDownMenu) { Rectangle rect = e.AffectedBounds; Graphics g = e.Graphics; rect.Width = OffsetMargin; if (e.ToolStrip.RightToLeft == RightToLeft.Yes) { rect.X -= 2; } else { rect.X += 2; } rect.Y += 1; rect.Height -= 2; g.SmoothingMode = SmoothingMode.AntiAlias; using (LinearGradientBrush brush = new LinearGradientBrush( rect, ColorTable.BackColorHover, Color.White, 90f)) { Blend blend = new Blend(); blend.Positions = new float[] { 0f, .2f, 1f }; blend.Factors = new float[] { 0f, 0.1f, .9f }; brush.Blend = blend; rect.Y += 1; rect.Height -= 2; using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, 8, RoundStyle.All, false)) { g.FillPath(brush, path); } } g.TextRenderingHint = TextRenderingHint.AntiAlias; StringFormat sf = new StringFormat(StringFormatFlags.NoWrap); Font font = new Font( e.ToolStrip.Font.FontFamily, 11, FontStyle.Bold); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; g.TranslateTransform(rect.X, rect.Bottom); g.RotateTransform(270f); if (!string.IsNullOrEmpty(MenuLogoString)) { Rectangle newRect = new Rectangle( rect.X, rect.Y, rect.Height, rect.Width); using (Brush brush = new SolidBrush(ColorTable.ForeColor)) { g.DrawString( MenuLogoString, font, brush, newRect, sf); } } g.ResetTransform(); return; } base.OnRenderImageMargin(e); }