protected override void OnPaint(PaintEventArgs pevent) { System.Drawing.Graphics g = pevent.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; g.Clear(BackColor); int dif = 60; Color DarkerChecked = Color.FromArgb(Math.Max(CheckedColor.R - dif, 0), Math.Max(CheckedColor.G - dif, 0), Math.Max(CheckedColor.B - dif, 0)); Color DarkerUnchecked = Color.FromArgb(Math.Max(UncheckedColor.R - dif, 0), Math.Max(UncheckedColor.G - dif, 0), Math.Max(UncheckedColor.B - dif, 0)); Color LighterChecked = Color.FromArgb( Math.Min(CheckedColor.R + dif, 255), Math.Min(CheckedColor.G + dif, 255), Math.Min(CheckedColor.B + dif, 255) ); Color LighterUnchecked = Color.FromArgb( Math.Min(UncheckedColor.R + dif, 255), Math.Min(UncheckedColor.G + dif, 255), Math.Min(UncheckedColor.B + dif, 255) ); var m = g.MeasureString(Text, Font); if (Checked) { if (CheckedColorIsLight) { g.FillRoundedRectangle(new SolidBrush(CheckedColor), new RectangleF(0, 0, Width - 1, Height - 1), 10); g.DrawRoundedRectangle(new Pen(DarkerChecked, 3), new RectangleF(1.5F, 1.5F, Width - 4, Height - 4), 10); } else { g.FillRoundedRectangle(new SolidBrush(LighterChecked), new RectangleF(0, 0, Width - 1, Height - 1), 10); g.DrawRoundedRectangle(new Pen(CheckedColor, 3), new RectangleF(1.5F, 1.5F, Width - 4, Height - 4), 10); } g.DrawString(Text, Font, new SolidBrush(CheckedTextColor), (Width - m.Width) / 2, (Height - m.Height) / 2); } else { if (UncheckedColorIsLight) { g.FillRoundedRectangle(new SolidBrush(DarkerUnchecked), new RectangleF(0, 0, Width - 1, Height - 1), 10); } else { g.FillRoundedRectangle(new SolidBrush(LighterUnchecked), new RectangleF(0, 0, Width - 1, Height - 1), 10); } g.DrawRoundedRectangle(new Pen(UncheckedColor, 3), new RectangleF(1.5F, 1.5F, Width - 4, Height - 4), 10); g.DrawString(Text, Font, new SolidBrush(UncheckedTextColor), (Width - m.Width) / 2, (Height - m.Height) / 2); } }
public static void DrawSelection(Graphics g, Rectangle r, Color c) { //we're attempting to closely emulate the Explorer::TreeView selection style //it renders to a rectangle 1 less wide and high r.Width -= 1; r.Height -= 1; float rounding = 2.0f; Brush brush = new LinearGradientBrush(r, AlphaBlend(20, c), AlphaBlend(120, c), LinearGradientMode.Vertical); g.FillRoundedRectangle(brush, r, rounding); g.SmoothingMode = SmoothingMode.AntiAlias; brush = new SolidBrush(Color.FromArgb(127 * c.A / 255, Color.White)); g.DrawRoundedRectangle(new Pen(brush, 1.0f), Rectangle.Inflate(r, -1, -1), rounding); brush = new SolidBrush(AlphaBlend(255, c)); g.DrawRoundedRectangle(new Pen(brush, 1.0f), r, rounding); }
public override void DrawFill(Graphics graphics) { using (Brush fillBrush = GetBrushForFill()) { graphics.FillRoundedRectangle(fillBrush, boxRect, 7); } }
public override void DrawShadow(Graphics graphics) { graphics.FillRoundedRectangle(Brushes.Gray, shadowRect, 7); }
public void paintThisShit(Graphics _graphics) { 警告重绘(); Bitmap offBm = new Bitmap(this.Size.Width, this.Size.Height); Graphics offerSreen = Graphics.FromImage(offBm);//定义画画到图片上 // Textformat StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; // Misc _graphics = Graphics.FromImage(offBm); LinearGradientBrush _StatusBrush = new LinearGradientBrush(GetStatusArea(), FirstColor, SecondColor, LinearGradientMode.Horizontal); SolidBrush _背景色Brush = new SolidBrush(_数值背景色); // Draw status if (StatusBarSize > 0) { _graphics.FillRoundedRectangle(_StatusBrush, this.GetStatusArea(), this.RoundedCornerAngle, RectangleEdgeFilter.BottomRight | RectangleEdgeFilter.BottomLeft); _graphics.DrawString(this.StatusText, this.StatusFont, Brushes.White, this.GetStatusArea(), f); } // Draw main background _graphics.FillRoundedRectangle(_背景色Brush, GetMainAreaBackground(), this.RoundedCornerAngle, RectangleEdgeFilter.TopLeft | RectangleEdgeFilter.TopRight); _graphics.DrawString(this.MainText, this.MainFont, Brushes.White, this.GetMainAreaBackground(), f); this.CreateGraphics().DrawImage(offBm, 0, 0);//贴出来显示 offBm.Dispose();//释放 offerSreen.Dispose(); // Clean up _StatusBrush.Dispose(); _背景色Brush.Dispose(); }
private void PaintHeader(Graphics g) { if (graphics == null) graphics = g; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; StringFormat sFormat = new StringFormat() { Alignment = Utils.Utils.TA2SA(_TextAlignment), LineAlignment = StringAlignment.Center }; Rectangle strRect = new Rectangle(); int FontPx = Utils.Utils.GetFontPixels(HeaderFont); int tmpShadowOffSet = Math.Min(Math.Min(_shadowOffSet, this.Width - 2), this.Height - 2); int tmpSoundCornerRadius = Math.Min(Math.Min(_roundCornerRadius, this.Width - 2), this.Height - 2); //Rectangle rect = headerRect = new Rectangle(0, 0, this.Width, HeaderHeight = HeaderHeight < FontPx ? FontPx : HeaderHeight); Rectangle rect = headerRect = new Rectangle(0, 0, this.Width - tmpShadowOffSet - 1, HeaderHeight = HeaderHeight < FontPx ? FontPx : HeaderHeight); switch(_TextAlignment) { case TextAlignment.Right:strRect = new Rectangle(0, 0, this.Width - tmpShadowOffSet - 1 - 10, HeaderHeight = HeaderHeight < FontPx ? FontPx : HeaderHeight); break; case TextAlignment.Center: strRect = rect; break; case TextAlignment.Left: strRect = new Rectangle(10, 0, this.Width - tmpShadowOffSet - 1, HeaderHeight = HeaderHeight < FontPx ? FontPx : HeaderHeight); break; } Brush brush = new SolidBrush(_HeaderColor); g.FillRoundedRectangle(brush, rect, HeaderCornerRadius > (HeaderHeight / 2) - 1 ? (HeaderHeight / 2) - 1 : HeaderCornerRadius, RectangleEdgeFilter.TopLeft | RectangleEdgeFilter.TopRight); g.DrawString(this.Text, HeaderFont, new SolidBrush(Color.White), strRect, sFormat); Point imgLoc = imagePt = new Point(this.Width - 16 - 10, (((HeaderHeight / 2) - (16 / 2))) + 1); Rectangle imgRect = imageRect = new Rectangle(imgLoc, new Size(16, 16)); //g.DrawLine(new Pen(new SolidBrush(SystemColors.ActiveBorder)), 0, HeaderHeight, 0, this.Height); //g.DrawLine(new Pen(new SolidBrush(SystemColors.ActiveBorder)), 0, this.Height - 1, this.Width, this.Height - 1); //g.DrawLine(new Pen(new SolidBrush(SystemColors.ActiveBorder)), this.Width - 1, this.Height - 1, this.Width - 1, HeaderHeight); if (region == null) region = new Region(rect); }
public void paintThisShit(Graphics _graphics) { // Textformat bool bTag1 = false; if (this.Parent.Tag.GetType() == typeof(int)) { if ((int)this.Parent.Tag == 1) { bTag1 = true; this.Height = this.Parent.Height - 30; m_txtSQLFilter.Width = this.Width - 86; if ((this.Height - 100) > 30) { m_txtSQLFilter.Height = this.Height - 100; } } } StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; // Textformat StringFormat fl = new StringFormat(); fl.Alignment = StringAlignment.Near; fl.LineAlignment = StringAlignment.Center; // Misc _graphics = this.CreateGraphics(); System.Drawing.Drawing2D.LinearGradientBrush _LeftAndRightBrush = new LinearGradientBrush(GetMainArea(), Color.DimGray, Color.Black, LinearGradientMode.Vertical); System.Drawing.Drawing2D.LinearGradientBrush _StatusBrush = new LinearGradientBrush(GetMainArea(), StatusColor1, StatusColor2, LinearGradientMode.Vertical); System.Drawing.Drawing2D.LinearGradientBrush _MainBrush = new LinearGradientBrush(GetMainArea(), FirstColor, SecondColor, LinearGradientMode.Vertical); // Draw left if (LeftBarSize > 0) { _graphics.FillRoundedRectangle(_LeftAndRightBrush, this.GetLeftArea(), this.RoundedCornerAngle, RectangleEdgeFilter.TopLeft | RectangleEdgeFilter.BottomLeft); _graphics.DrawString(this.LeftText, this.Font, Brushes.White, this.GetLeftArea(), f); } // Draw status if (StatusBarSize > 0) { _graphics.FillRoundedRectangle(_StatusBrush, this.GetStatusArea(), this.RoundedCornerAngle, RectangleEdgeFilter.None); _graphics.DrawString(this.StatusText, this.Font, Brushes.White, this.GetStatusArea(), f); } // Draw main background _graphics.FillRoundedRectangle(Brushes.DimGray, GetMainAreaBackground(), this.RoundedCornerAngle, RectangleEdgeFilter.None); // Draw main //_graphics.FillRoundedRectangle(_MainBrush, this.GetMainArea(), this.RoundedCornerAngle, RectangleEdgeFilter.None); //_graphics.DrawString(this.MainText, this.Font, Brushes.White, this.GetMainAreaBackground(), f); if (bTag1) { _graphics.DrawString(ColTitleLong, this.Font, Brushes.White, this.GetMainAreaEx(), fl); } else { _graphics.DrawString(this.MainText, this.Font, Brushes.White, this.GetMainAreaEx(), fl); } // Draw right if (RightBarSize > 0) { _graphics.FillRoundedRectangle(_LeftAndRightBrush, this.GetRightArea(), this.RoundedCornerAngle, RectangleEdgeFilter.TopRight | RectangleEdgeFilter.BottomRight); _graphics.DrawString(this.RightText, this.Font, Brushes.White, this.GetRightArea(), f); } // Clean up _LeftAndRightBrush.Dispose(); _MainBrush.Dispose(); _StatusBrush.Dispose(); }
public override void Paint(Graphics graphics, Revision revision, Rectangle rect) { const float Radius = 3; _drawnReferences.Clear(); PaintHeader(graphics, Resources.StrRefs.AddColon(), rect); var font = GitterApplication.FontManager.UIFont.Font; var r2 = new Rectangle(rect.X + HeaderWidth, rect.Y, rect.Width - HeaderWidth, rect.Height); r2.Y += GetYOffset(font); int offset = 0; using(var tagBrush = new SolidBrush(ColorScheme.TagBackColor)) using(var localBrush = new SolidBrush(ColorScheme.LocalBranchBackColor)) using(var remoteBrush = new SolidBrush(ColorScheme.RemoteBranchBackColor)) { lock(revision.References.SyncRoot) { foreach(var reference in revision.References) { var name = ((INamedObject)reference).Name; var size = GitterApplication.TextRenderer.MeasureText( graphics, name, font, int.MaxValue, ContentFormat); var r = new Rectangle(r2.X + offset, r2.Y, size.Width + 6, DefaultElementHeight - 1); Brush brush; switch(reference.Type) { case ReferenceType.LocalBranch: brush = localBrush; break; case ReferenceType.RemoteBranch: brush = remoteBrush; break; case ReferenceType.Tag: brush = tagBrush; break; default: brush = Brushes.WhiteSmoke; break; } graphics.FillRoundedRectangle(brush, Pens.Black, r, Radius); var textRect = new Rectangle(r2.X + offset + 3, r2.Y, size.Width + 5, size.Height); GitterApplication.TextRenderer.DrawText( graphics, name, font, SystemBrushes.WindowText, textRect, ContentFormat); _drawnReferences.AddLast(new ReferenceVisual(reference, r)); offset += size.Width + 3 + 6; } } } }
// Example code taken from here : http://www.codeproject.com/Articles/38436/Extended-Graphics-Rounded-rectangles-Font-metrics // Wanted to test the graphics path and LinearGradientBrush code together. void RoundeRectangle1(Graphics g) { var width = this.ClientRectangle.Width; var height = this.ClientRectangle.Height; var GradientInactiveCaption = Color.FromArgb (255, 215, 228, 242); var GradientActiveCaptionDark2 = Color.FromArgb (255, 52, 112, 171); var GradientActiveCaptionDark5 = Color.FromArgb (255, 33, 79, 107); var InactiveBorderLight = Color.FromArgb (255, 143, 247, 253); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillRoundedRectangle(new SolidBrush(GradientActiveCaptionDark2), 10, 10, width - 40, height - 60, 10); LinearGradientBrush brush = new LinearGradientBrush( new Point(width/2, 0), new Point(width/2, height), GradientInactiveCaption, GradientActiveCaptionDark5 ); g.FillRoundedRectangle(brush, 12, 12, width - 44, height - 64, 10); g.DrawRoundedRectangle(new Pen(InactiveBorderLight), 12, 12, width - 44, height - 64, 10); g.FillRoundedRectangle(new SolidBrush(Color.FromArgb(100, 70, 130, 180)), 12, 12 + ((height - 64) / 2), width - 44, (height - 64)/2, 10); }
private void PaintDiffStats(Graphics graphics, Font font, Brush textBrush, Rectangle rect) { const int squares = 10; const int squareWidth = 4; const int squareHeight = 13; const int squareSpacing = 1; const float radius = 1.5f; var oldMode = graphics.SmoothingMode; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if(_file.IsBinary) { var rc = new Rectangle( rect.Right - squareWidth * squares - squareSpacing * (squares - 1), rect.Y + (rect.Height - squareHeight) / 2, squareWidth * squares + squareSpacing * (squares - 1), squareHeight); graphics.FillRoundedRectangle(Brushes.Gray, rc, radius); GitterApplication.TextRenderer.DrawText( graphics, Resources.StrlBinary, font, textBrush, rc, DiffStatCenterFormat); } else { var added = _file.Stats.AddedLinesCount; var removed = _file.Stats.RemovedLinesCount; var changed = added + removed; int n1, n2; if(changed == 0 && _file.Status == FileStatus.Renamed) { var rc = new Rectangle( rect.Right - squareWidth * squares - squareSpacing * (squares - 1), rect.Y + (rect.Height - squareHeight) / 2, squareWidth * squares + squareSpacing * (squares - 1), squareHeight); graphics.FillRoundedRectangle(Brushes.DarkCyan, rc, radius); GitterApplication.TextRenderer.DrawText( graphics, Resources.StrlRename, font, Color.White, rc, DiffStatCenterFormat); } else if(changed == 0 && _file.Status == FileStatus.Copied) { var rc = new Rectangle( rect.Right - squareWidth * squares - squareSpacing * (squares - 1), rect.Y + (rect.Height - squareHeight) / 2, squareWidth * squares + squareSpacing * (squares - 1), squareHeight); graphics.FillRoundedRectangle(Brushes.DarkGreen, rc, radius); GitterApplication.TextRenderer.DrawText( graphics, Resources.StrlCopy, font, Color.White, rc, DiffStatCenterFormat); } else { var rc = new Rectangle( rect.Right - squareWidth, rect.Y + (rect.Height - squareHeight) / 2, squareWidth, squareHeight); if(changed <= squares) { n1 = added; n2 = removed; } else { n1 = added * squares / changed; n2 = removed * squares / changed; } int n3 = squares - n1 - n2; Brush brush; for(int i = 0; i < squares; ++i) { if(n3 != 0) { brush = Brushes.Gray; --n3; } else if(n2 != 0) { brush = Brushes.Red; --n2; } else { brush = Brushes.Green; --n1; } graphics.FillRoundedRectangle(brush, rc, radius); rc.X -= squareWidth + squareSpacing; } rect.Width -= (squareWidth + squareSpacing) * squares + 2; if(rect.Width > 2) { GitterApplication.TextRenderer.DrawText( graphics, changed.ToString(System.Globalization.CultureInfo.InvariantCulture), font, textBrush, rect, DiffStatFormat); } } } graphics.SmoothingMode = oldMode; }
private static void PaintDockMarkerButtonBackground(Graphics graphics, Rectangle bounds, bool hover) { Color start, end, border; if(hover) { start = ColorTable.DockMarkerButtonBackgroundStart; end = ColorTable.DockMarkerButtonBackgroundEnd; border = ColorTable.DockMarkerButtonBorder; } else { start = Color.FromArgb((byte)(ViewConstants.OpacityNormal * 255), ColorTable.DockMarkerButtonBackgroundStart.R, ColorTable.DockMarkerButtonBackgroundStart.G, ColorTable.DockMarkerButtonBackgroundStart.B); end = Color.FromArgb((byte)(ViewConstants.OpacityNormal * 255), ColorTable.DockMarkerButtonBackgroundEnd.R, ColorTable.DockMarkerButtonBackgroundEnd.G, ColorTable.DockMarkerButtonBackgroundEnd.B); border = Color.FromArgb((byte)(ViewConstants.OpacityNormal * 255), ColorTable.DockMarkerButtonBorder.R, ColorTable.DockMarkerButtonBorder.G, ColorTable.DockMarkerButtonBorder.B); } using(var pen = new Pen(border)) using(var brush = new LinearGradientBrush(bounds, start, end, LinearGradientMode.Vertical)) { graphics.FillRoundedRectangle(brush, pen, bounds, 2); } }
private static void RenderMenuItemBackgroundInternal(Graphics graphics, int x, int y, int width, int height, bool pressed, bool selected, bool root) { var rc = new Rectangle(x, y, width - 1, height - 1); if(pressed) { if(root) { rc.Height += 4; using(var pen = new Pen(ColorTable.RootMenuItemPressedBorder)) using(var brush = new SolidBrush(ColorTable.RootMenuItemPressedBackground)) { graphics.FillRoundedRectangle(brush, pen, rc, 2); } } else { rc.Offset(2, 1); rc.Width -= 2; rc.Height -= 1; using(var pen = new Pen(ColorTable.MenuItemSelectedBorder)) using(var brush = new LinearGradientBrush(rc, ColorTable.MenuItemSelectedBackgroundStart, ColorTable.MenuItemSelectedBackgroundEnd, LinearGradientMode.Vertical)) { graphics.FillRoundedRectangle(brush, pen, rc, 2); } } } else if(selected) { if(root) { rc.Offset(1, 1); rc.Width -= 1; } else { rc.Offset(2, 1); rc.Width -= 2; } rc.Height -= 1; using(var pen = new Pen(ColorTable.MenuItemSelectedBorder)) using(var brush = new LinearGradientBrush(rc, ColorTable.MenuItemSelectedBackgroundStart, ColorTable.MenuItemSelectedBackgroundEnd, LinearGradientMode.Vertical)) { graphics.FillRoundedRectangle(brush, pen, rc, 2); } } }
private void PaintDockMarkerButtonBackground(Graphics graphics, Rectangle bounds, bool hover) { Color backgroundColor; if(hover) { backgroundColor = ColorTable.DockMarkerButtonBackground; } else { backgroundColor = Color.FromArgb((byte)(ViewConstants.OpacityNormal * 255), ColorTable.DockMarkerButtonBackground); } var oldMode = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.HighQuality; using(var brush = new SolidBrush(backgroundColor)) { graphics.FillRoundedRectangle(brush, bounds, 2); } graphics.SmoothingMode = oldMode; }
public void paintThis(Graphics _graphics) { // Textformat StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; f.LineAlignment = StringAlignment.Center; // Misc _graphics = this.CreateGraphics(); System.Drawing.Drawing2D.LinearGradientBrush _LeftAndRightBrush = new LinearGradientBrush(GetMainArea(), Color.DimGray, Color.Black, LinearGradientMode.Vertical); System.Drawing.Drawing2D.LinearGradientBrush _StatusBrush = new LinearGradientBrush(GetMainArea(), StatusColor1, StatusColor2, LinearGradientMode.Vertical); System.Drawing.Drawing2D.LinearGradientBrush _MainBrush = new LinearGradientBrush(GetMainArea(), FirstColor, SecondColor, LinearGradientMode.Vertical); // Draw left if (LeftBarSize > 0) { _graphics.FillRoundedRectangle(_LeftAndRightBrush, this.GetLeftArea(), this.RoundedCornerAngle, RectangleEdgeFilter.TopLeft | RectangleEdgeFilter.BottomLeft); _graphics.DrawString(this.LeftText, this.Font, Brushes.White, this.GetLeftArea(), f); } // Draw status if (StatusBarSize > 0) { _graphics.FillRoundedRectangle(_StatusBrush, this.GetStatusArea(), this.RoundedCornerAngle, RectangleEdgeFilter.None); _graphics.DrawString(this.StatusText, this.Font, Brushes.White, this.GetStatusArea(), f); } // Draw main background _graphics.FillRoundedRectangle(Brushes.DimGray, GetMainAreaBackground(), this.RoundedCornerAngle, RectangleEdgeFilter.None); // Draw main _graphics.FillRoundedRectangle(_MainBrush, this.GetMainArea(), this.RoundedCornerAngle, RectangleEdgeFilter.None); _graphics.DrawString(this.MainText, this.Font, Brushes.White, this.GetMainAreaBackground(), f); // Draw right if (RightBarSize > 0) { _graphics.FillRoundedRectangle(_LeftAndRightBrush, this.GetRightArea(), this.RoundedCornerAngle, RectangleEdgeFilter.TopRight | RectangleEdgeFilter.BottomRight); _graphics.DrawString(this.RightText, this.Font, Brushes.White, this.GetRightArea(), f); } // Clean up _LeftAndRightBrush.Dispose(); _MainBrush.Dispose(); _StatusBrush.Dispose(); }