protected override void OnPaint(PaintEventArgs e) { //UpdateColors(); Bitmap B = new Bitmap(Width, Height); Graphics G = Graphics.FromImage(B); W = Width - 1; H = Height - 1; Rectangle Base = new Rectangle(0, 24, W, H); GraphicsPath GP = new GraphicsPath(); GraphicsPath GP2 = new GraphicsPath(); GraphicsPath GP3 = new GraphicsPath(); var _with15 = G; _with15.SmoothingMode = SmoothingMode.HighQuality; _with15.PixelOffsetMode = PixelOffsetMode.HighQuality; _with15.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; _with15.Clear(BackColor); //-- Progress Value //int iValue = Convert.ToInt32(((float)_Value) / ((float)(_Maximum * Width))); float percent = ((float)_Value) / ((float)_Maximum); int iValue = (int)(percent * ((float)Width)); switch (Value) { case 0: //-- Base _with15.FillRectangle(new SolidBrush(_BaseColor), Base); //--Progress _with15.FillRectangle(new SolidBrush(_ProgressColor), new Rectangle(0, 24, iValue - 1, H - 1)); break; case 100: //-- Base _with15.FillRectangle(new SolidBrush(_BaseColor), Base); //--Progress _with15.FillRectangle(new SolidBrush(_ProgressColor), new Rectangle(0, 24, iValue - 1, H - 1)); break; default: //-- Base _with15.FillRectangle(new SolidBrush(_BaseColor), Base); //--Progress GP.AddRectangle(new Rectangle(0, 24, iValue - 1, H - 1)); _with15.FillPath(new SolidBrush(_ProgressColor), GP); if (_Pattern) { //-- Hatch Brush HatchBrush HB = new HatchBrush(HatchStyle.Plaid, _DarkerProgress, _ProgressColor); _with15.FillRectangle(HB, new Rectangle(0, 24, iValue - 1, H - 1)); } if (_ShowBalloon) { //-- Balloon Rectangle Balloon = new Rectangle(iValue - 18, 0, 34, 16); GP2 = ForeverLibrary.RoundRec(Balloon, 4); _with15.FillPath(new SolidBrush(_BaseColor), GP2); //-- Arrow GP3 = ForeverLibrary.DrawArrow(iValue - 9, 16, true); _with15.FillPath(new SolidBrush(_BaseColor), GP3); //-- Value > You can add "%" > value & "%" string text = (_PercentSign ? Value.ToString() + "%" : Value.ToString()); int wOffset = (_PercentSign ? iValue - 15 : iValue - 11); _with15.DrawString(text, new Font("Segoe UI", 10), new SolidBrush(ForeColor), new Rectangle(wOffset, -2, W, H), ForeverLibrary.NearSF); } break; } base.OnPaint(e); G.Dispose(); e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.DrawImageUnscaled(B, 0, 0); B.Dispose(); }
internal override void AddToGraphicsPath(GraphicsPath path) { path.AddRectangle(Rectangle); }
private static GraphicsPath GenerateRoundedRectangle( this Graphics graphics, RectangleF rectangle, float radius, RectangleEdgeFilter filter) { float diameter; GraphicsPath path = new GraphicsPath(); if (radius <= 0.0F || filter == RectangleEdgeFilter.None) { path.AddRectangle(rectangle); path.CloseFigure(); return(path); } else { if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0) { return(graphics.GenerateCapsule(rectangle)); } diameter = radius * 2.0F; SizeF sizeF = new SizeF(diameter, diameter); RectangleF arc = new RectangleF(rectangle.Location, sizeF); if ((RectangleEdgeFilter.TopLeft & filter) == RectangleEdgeFilter.TopLeft) { path.AddArc(arc, 180, 90); } else { path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y); path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y); } arc.X = rectangle.Right - diameter; if ((RectangleEdgeFilter.TopRight & filter) == RectangleEdgeFilter.TopRight) { path.AddArc(arc, 270, 90); } else { path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y); path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X + arc.Width, arc.Y); } arc.Y = rectangle.Bottom - diameter; if ((RectangleEdgeFilter.BottomRight & filter) == RectangleEdgeFilter.BottomRight) { path.AddArc(arc, 0, 90); } else { path.AddLine(arc.X + arc.Width, arc.Y, arc.X + arc.Width, arc.Y + arc.Height); path.AddLine(arc.X, arc.Y + arc.Height, arc.X + arc.Width, arc.Y + arc.Height); } arc.X = rectangle.Left; if ((RectangleEdgeFilter.BottomLeft & filter) == RectangleEdgeFilter.BottomLeft) { path.AddArc(arc, 90, 90); } else { path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X, arc.Y + arc.Height); path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y); } path.CloseFigure(); } return(path); }
private void CalculateRegion() { if (backgroundStyle == SignalStrengthBackgroundStyle.Normal) { GraphicsPath gp = new GraphicsPath(); gp.AddRectangle(ClientRectangle); this.Region = new Region(gp); } else { GraphicsPath myGP = new GraphicsPath(); float startX = 0.0f; float startY = 0.0f; float stepX = 0.0f; float stepY = 0.0f; float barWidth = 0.0f; float barHeight = 0.0f; RectangleF barRect; float calcBarStep = 0.0f; float barHeightStep = 0.0f; if (barLayout == SignalStrengthLayout.LeftToRight) { calcBarStep = (this.Height - smallBarHeight) / numberOfBars; startX = barSpacing / 2.0f; barWidth = this.Width / numberOfBars - barSpacing; if (barWidth <= 0) { barWidth = 1; } startY = this.Height - smallBarHeight; stepX = barWidth + barSpacing; stepY = -calcBarStep; barHeight = smallBarHeight; barHeightStep = calcBarStep; } else if (barLayout == SignalStrengthLayout.RightToLeft) { calcBarStep = (this.Height - smallBarHeight) / numberOfBars; barWidth = this.Width / numberOfBars - barSpacing; startX = this.Width - (barSpacing / 2.0f) - barWidth; if (barWidth <= 0) { barWidth = 1; } startY = this.Height - smallBarHeight; stepX = -(barWidth + barSpacing); stepY = -calcBarStep; barHeight = smallBarHeight; barHeightStep = calcBarStep; } else if (barLayout == SignalStrengthLayout.TopToBottom) { calcBarStep = (this.Width - smallBarHeight) / numberOfBars; barWidth = this.Height / numberOfBars - barSpacing; if (barWidth <= 0) { barWidth = 0; } startX = 0; startY = 0; stepX = 0; stepY = barWidth + barSpacing; barHeight = smallBarHeight; barHeightStep = calcBarStep; } else { calcBarStep = (this.Width - smallBarHeight) / numberOfBars; barWidth = this.Height / numberOfBars - barSpacing; if (barWidth <= 0) { barWidth = 0; } startX = 0; startY = this.Height - barWidth; stepX = 0; stepY = -(barWidth + barSpacing); barHeight = smallBarHeight; barHeightStep = calcBarStep; } for (int i = 0; i < numberOfBars; i++) { if (barLayout == SignalStrengthLayout.LeftToRight || barLayout == SignalStrengthLayout.RightToLeft) { barRect = new RectangleF(startX, startY, barWidth, barHeight); } else { barRect = new RectangleF(startX, startY, barHeight, barWidth); } myGP.AddRectangle(barRect); startX += stepX; startY += stepY; barHeight += calcBarStep; } this.Region = new Region(myGP); } }
/// <summary> /// 建立带有圆角样式的路径。 /// </summary> /// <param name="rect">用来建立路径的矩形。</param> /// <param name="_radius">圆角的大小。</param> /// <param name="style">圆角的样式。</param> /// <param name="correction">是否把矩形长宽减 1,以便画出边框。</param> /// <returns>建立的路径。</returns> public static GraphicsPath CreatePath( Rectangle rect, int radius, RoundStyle style, bool correction) { GraphicsPath path = new GraphicsPath(); int radiusCorrection = correction ? 1 : 0; switch (style) { case RoundStyle.None: path.AddRectangle(rect); break; case RoundStyle.All: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); break; case RoundStyle.Left: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddLine( rect.Right - radiusCorrection, rect.Y, rect.Right - radiusCorrection, rect.Bottom - radiusCorrection); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); break; case RoundStyle.Right: path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddLine(rect.X, rect.Bottom - radiusCorrection, rect.X, rect.Y); break; case RoundStyle.Top: path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc( rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270, 90); path.AddLine( rect.Right - radiusCorrection, rect.Bottom - radiusCorrection, rect.X, rect.Bottom - radiusCorrection); break; case RoundStyle.Bottom: path.AddArc( rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0, 90); path.AddArc( rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90, 90); path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y); break; } path.CloseFigure(); return(path); }
public static GraphicsPath RoundRect(Rectangle Rect, int Rounding, RoundingStyle Style = RoundingStyle.All) { GraphicsPath GP = new GraphicsPath(); int AW = Rounding * 2; GP.StartFigure(); if (Rounding == 0) { GP.AddRectangle(Rect); GP.CloseAllFigures(); return GP; } switch (Style) { case RoundingStyle.All: GP.AddArc(new Rectangle(Rect.X, Rect.Y, AW, AW), -180, 90); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90); GP.AddArc(new Rectangle(Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 90, 90); break; case RoundingStyle.Top: GP.AddArc(new Rectangle(Rect.X, Rect.Y, AW, AW), -180, 90); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90); GP.AddLine(new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y + Rect.Height)); break; case RoundingStyle.Bottom: GP.AddLine(new Point(Rect.X, Rect.Y), new Point(Rect.X + Rect.Width, Rect.Y)); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90); GP.AddArc(new Rectangle(Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 90, 90); break; case RoundingStyle.Left: GP.AddArc(new Rectangle(Rect.X, Rect.Y, AW, AW), -180, 90); GP.AddLine(new Point(Rect.X + Rect.Width, Rect.Y), new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height)); GP.AddArc(new Rectangle(Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 90, 90); break; case RoundingStyle.Right: GP.AddLine(new Point(Rect.X, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y)); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90); break; case RoundingStyle.TopRight: GP.AddLine(new Point(Rect.X, Rect.Y + 1), new Point(Rect.X, Rect.Y)); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90); GP.AddLine(new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height - 1), new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height)); GP.AddLine(new Point(Rect.X + 1, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y + Rect.Height)); break; case RoundingStyle.BottomRight: GP.AddLine(new Point(Rect.X, Rect.Y + 1), new Point(Rect.X, Rect.Y)); GP.AddLine(new Point(Rect.X + Rect.Width - 1, Rect.Y), new Point(Rect.X + Rect.Width, Rect.Y)); GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90); GP.AddLine(new Point(Rect.X + 1, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y + Rect.Height)); break; } GP.CloseAllFigures(); return GP; }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics _graphics = e.Graphics; _graphics.Clear(Parent.BackColor); _graphics.SmoothingMode = SmoothingMode.HighQuality; _graphics.TextRenderingHint = TextStyle.TextRenderingHint; Rectangle _clientRectangle = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1); ControlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(_clientRectangle, _border); _graphics.FillRectangle(new SolidBrush(BackColor), new Rectangle(ClientRectangle.X - 1, ClientRectangle.Y - 1, ClientRectangle.Width + 1, ClientRectangle.Height + 1)); _graphics.SetClip(ControlGraphicsPath); _buttonRectangle = new Rectangle(Width - _buttonWidth, 1, _buttonWidth, Height); Size incrementSize = TextManager.MeasureText("+", _buttonFont, _graphics); Size decrementSize = TextManager.MeasureText("-", _buttonFont, _graphics); _incrementButtonPoints[0] = new Point((_buttonRectangle.X + (_buttonRectangle.Width / 2)) - (incrementSize.Width / 2), (_buttonRectangle.Y + (_buttonRectangle.Height / 2)) - (_buttonRectangle.Height / 4) - (incrementSize.Height / 2)); _decrementButtonPoints[0] = new Point((_buttonRectangle.X + (_buttonRectangle.Width / 2)) - (decrementSize.Width / 2), (_buttonRectangle.Y + (_buttonRectangle.Height / 2) + (_buttonRectangle.Height / 4)) - (decrementSize.Height / 2)); _incrementButtonPoints[1] = new Point((_buttonRectangle.X + (_buttonRectangle.Width / 4)) - (incrementSize.Width / 2), (Height / 2) - (incrementSize.Height / 2)); _decrementButtonPoints[1] = new Point((_buttonRectangle.X + (_buttonRectangle.Width / 2) + (_buttonRectangle.Width / 4)) - (decrementSize.Width / 2), (Height / 2) - (decrementSize.Height / 2)); int toggleInt; switch (_buttonOrientation) { case Orientation.Horizontal: { toggleInt = 1; _borderButtons.Location = new Point(_buttonRectangle.X + (_buttonRectangle.Width / 2), _border.Thickness); _borderButtons.Size = new Size(1, Height - _border.Thickness - 1); break; } case Orientation.Vertical: { toggleInt = 0; _borderButtons.Location = new Point(_buttonRectangle.X, (_buttonRectangle.Bottom / 2) - _border.Thickness); _borderButtons.Size = new Size(Width - _border.Thickness - 1, 1); break; } default: { throw new ArgumentOutOfRangeException(); } } _buttonPath = new GraphicsPath(); _buttonPath.AddRectangle(_buttonRectangle); _buttonPath.CloseAllFigures(); Color _backColor = Enabled ? BackColorState.Enabled : BackColorState.Disabled; VisualBackgroundRenderer.DrawBackground(e.Graphics, _backColor, BackgroundImage, MouseState, _clientRectangle, Border); _graphics.SetClip(ControlGraphicsPath); _graphics.FillRectangle(new SolidBrush(_buttonColor), _buttonRectangle); _graphics.ResetClip(); _graphics.DrawString("+", _buttonFont, new SolidBrush(_buttonForeColor), _incrementButtonPoints[toggleInt]); _graphics.DrawString("-", _buttonFont, new SolidBrush(_buttonForeColor), _decrementButtonPoints[toggleInt]); _borderEdge.Location = new Point(_buttonRectangle.X, _border.Thickness); _borderEdge.Size = new Size(1, Height - _border.Thickness - 1); DrawText(_graphics); VisualBorderRenderer.DrawBorderStyle(e.Graphics, _border, ControlGraphicsPath, MouseState); }
/// <summary> /// Creates a rectangular <see cref="GraphicsPath"/> with rounded edges, optionally with an open title /// region specified by the parameters <paramref name="titleInset"/> and <paramref name="titleWidth"/>. /// </summary> /// <param name="baseRect">The rect which surrounds the created path.</param> /// <param name="radiusX">The X radius of the rounded edges.</param> /// <param name="radiusY">The Y radius of the rounded edges.</param> /// <param name="withTitleRegion">If set to <c>true</c>, a title region will be left out.</param> /// <param name="titleInset">Inset of the title region behind the corner. This parameter will only be used if /// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param> /// <param name="titleWidth">Width of the title region to leave out. This parameter will only be used if /// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param> public static GraphicsPath CreateRoundedRectWithTitleRegionPath(RectangleF baseRect, float radiusX, float radiusY, bool withTitleRegion, float titleInset, float titleWidth) { GraphicsPath result = new GraphicsPath(); if (radiusX <= 0.0f && radiusY <= 0.0f || baseRect.Width == 0 || baseRect.Height == 0) { // if corner radius is less than or equal to zero, return the original rectangle if (withTitleRegion) { // If we should leave out a title region, we need to do it manually, because we need to start next to the // title. titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * titleInset); // Right from the title to the upper right edge result.AddLine(baseRect.Left + 2 * titleInset + titleWidth, baseRect.Top, baseRect.Right, baseRect.Top); // Upper right edge to lower right edge result.AddLine(baseRect.Right, baseRect.Top, baseRect.Right, baseRect.Bottom); // Lower right edge to lower left edge result.AddLine(baseRect.Right, baseRect.Bottom, baseRect.Left, baseRect.Bottom); // Lower left edge to upper left edge result.AddLine(baseRect.Left, baseRect.Bottom, baseRect.Left, baseRect.Top); // Upper left edge to the left side of the title result.AddLine(baseRect.Left, baseRect.Top, baseRect.Left + titleInset, baseRect.Top); } else { result.AddRectangle(baseRect); } } else { if (radiusX >= baseRect.Width / 2f) { radiusX = baseRect.Width / 2f; } if (radiusY >= baseRect.Height / 2f) { radiusY = baseRect.Height / 2f; } // create the arc for the rectangle sides and declare a graphics path object for the drawing SizeF sizeF = new SizeF(radiusX * 2f, radiusY * 2f); RectangleF arc = new RectangleF(baseRect.Location, sizeF); if (withTitleRegion) { titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * (radiusX + titleInset)); // Right of the title to the upper right edge result.AddLine(baseRect.Left + radiusX + titleInset + titleWidth, baseRect.Top, baseRect.Right - radiusX, baseRect.Top); } // Top right arc arc.X = baseRect.Right - radiusX * 2f; result.AddArc(arc, 270, 90); // Bottom right arc arc.Y = baseRect.Bottom - radiusY * 2f; result.AddArc(arc, 0, 90); // Bottom left arc arc.X = baseRect.Left; result.AddArc(arc, 90, 90); // Top left arc arc.Y = baseRect.Top; result.AddArc(arc, 180, 90); if (withTitleRegion) { // Upper left edge to the left side of the title result.AddLine(baseRect.Left + radiusX, baseRect.Top, baseRect.Left + radiusX + titleInset, baseRect.Top); } else { result.CloseFigure(); } } result.Flatten(); return(result); }
internal void Transform(Matrix matrix) { if (matrix.IsIdentity) { return; // bail out } byte[] oldData = (byte[])Data.Clone(); // this.Clone().Data ; int oldSize = 8 + GetInt32(oldData, 0); int nrOps2 = GetInt32(oldData, 12); int readPointer = StartRegionData(); int writePointer = readPointer; float m11 = matrix.Elements[0]; float m12 = matrix.Elements[1]; float m21 = matrix.Elements[2]; float m22 = matrix.Elements[3]; float dX = matrix.Elements[4]; float dY = matrix.Elements[5]; while (readPointer < oldSize) { Token T = NextToken(oldData, ref readPointer, false); int tokenType = GetInt32(T.rawData, 0); switch (tokenType) { case REG_RECT: { RectangleF rect = GetRectangle(T.rawData); if ((m12 == 0.0f) && (m21 == 0.0f)) { // in this case, rect transforms to another rectangle rect.X = (m11 < 0) ? m11 * (rect.X + rect.Width) : m11 * rect.X; rect.X += dX; /* there is actually a BUG in Microsoft's .NET * 1.1 implementation: * for (m22<0) they evaluate rect.Y to be * m22*(rect.Y+rect.Height), which cannot be possible * by simple geometric reasoning... */ rect.Y = (m22 < 0) ? m22 * (rect.Y - rect.Height) : m22 * rect.Y; rect.Y += dY; rect.Width = (m11 < 0) ? -m11 * rect.Width : m11 * rect.Width; rect.Height = (m22 < 0) ? -m22 * rect.Height : m22 * rect.Height; writePointer = AddRegionRectangle(rect, writePointer); } else { // rectangular shape is not preserved -> use a graphics path GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); path.Transform(matrix); writePointer = AddRegionPath(path, writePointer); } } break; case REG_PATH: { GraphicsPath path = GetPath(T.rawData); path.Transform(matrix); writePointer = AddRegionPath(path, writePointer); } break; default: { // other tokens are not concerned writePointer = AddRawData(T.rawData, writePointer); } break; } } WriteHeader(writePointer - 8, nrOps2); Resize(writePointer); }
/// <summary> /// Adds rectangle to a graph path /// </summary> /// <param name="graphicPath">Graph path to be added</param> /// <param name="dx">X region</param> /// <param name="dy">Y region</param> /// <param name="zoom">Zoom value</param> public override void AddToGraphPath(GraphicsPath graphicPath, int dx, int dy, float zoom) { graphicPath.AddRectangle(this.region.GetRectangleF(dx, dy, zoom)); }
private void OnDrawTabPage(Graphics g, FATabStripItem currentItem) { bool isFirstTab = Items.IndexOf(currentItem) == 0; Font currentFont = Font; if (currentItem == SelectedItem) { currentFont = new Font(Font, FontStyle.Bold); } SizeF textSize = g.MeasureString(currentItem.Title, SystemFonts.DefaultFont, new SizeF(200, 10), sf); textSize.Width += 20; RectangleF buttonRect = currentItem.StripRect; GraphicsPath path = new GraphicsPath(); LinearGradientBrush brush; int mtop = 3; #region Draw Not Right-To-Left Tab if (RightToLeft == RightToLeft.No) { //if (currentItem == SelectedItem || isFirstTab) //{ // path.AddLine(buttonRect.Left - 10, buttonRect.Bottom - 1, // buttonRect.Left + (buttonRect.Height/2) - 4, mtop + 4); //} //else //{ // path.AddLine(buttonRect.Left, buttonRect.Bottom - 1, buttonRect.Left, // buttonRect.Bottom - (buttonRect.Height/2) - 2); // path.AddLine(buttonRect.Left, buttonRect.Bottom - (buttonRect.Height/2) - 3, // buttonRect.Left + (buttonRect.Height/2) - 4, mtop + 3); //} //path.AddLine(buttonRect.Left + (buttonRect.Height/2) + 2, mtop, buttonRect.Right - 3, mtop); //path.AddLine(buttonRect.Right, mtop + 2, buttonRect.Right, buttonRect.Bottom - 1); //path.AddLine(buttonRect.Right - 4, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - 1); path.AddRectangle(buttonRect); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ActiveCaption, SystemColors.ActiveCaption, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.InactiveCaption, SystemColors.InactiveCaption, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(new Pen(brush, 1), path); //if (currentItem == SelectedItem) //{ // g.DrawLine(new Pen(brush), buttonRect.Left, buttonRect.Height + 2, // buttonRect.Left + buttonRect.Width, buttonRect.Height + 2); //} double dpiscale = g.DpiX / 96.0; var tmargin = 15 * (float)(dpiscale + 0.3) / 2; PointF textLoc = new PointF(buttonRect.Left + tmargin, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2); RectangleF textRect = buttonRect; textRect.Location = textLoc; //textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 4; //textRect.Height = textSize.Height + currentFont.Size/2; if (currentItem == SelectedItem) { //textRect.Y -= 2; g.DrawString(currentItem.Title, SystemFonts.DefaultFont, new SolidBrush(SystemColors.ActiveCaptionText), textRect, sf); } else { g.DrawString(currentItem.Title, SystemFonts.DefaultFont, new SolidBrush(SystemColors.ActiveCaptionText), textRect, sf); } } #endregion #region Draw Right-To-Left Tab if (RightToLeft == RightToLeft.Yes) { if (currentItem == SelectedItem || isFirstTab) { path.AddLine(buttonRect.Right + 10, buttonRect.Bottom - 1, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 4); } else { path.AddLine(buttonRect.Right, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 2); path.AddLine(buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 3); } path.AddLine(buttonRect.Right - (buttonRect.Height / 2) - 2, mtop, buttonRect.Left + 3, mtop); path.AddLine(buttonRect.Left, mtop + 2, buttonRect.Left, buttonRect.Bottom - 1); path.AddLine(buttonRect.Left + 4, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - 1); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Window, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(SystemPens.ControlDark, path); if (currentItem == SelectedItem) { g.DrawLine(new Pen(brush), buttonRect.Right + 9, buttonRect.Height + 2, buttonRect.Right - buttonRect.Width + 1, buttonRect.Height + 2); } PointF textLoc = new PointF(buttonRect.Left + 2, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2); RectangleF textRect = buttonRect; textRect.Location = textLoc; textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 10; textRect.Height = textSize.Height + currentFont.Size / 2; if (currentItem == SelectedItem) { textRect.Y -= 1; g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } else { g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } //g.FillRectangle(Brushes.Red, textRect); } #endregion currentItem.IsDrawn = true; }
private static void DrawConnectivityRegion(GraphicsPath path, TileConnection connectivity, Rectangle baseRect) { if (connectivity == TileConnection.None) { return; } Rectangle fullRect = baseRect; Rectangle centerRect = GetConnectivityRegionRect(TileConnection.None, baseRect); // Add rects for the 4-neighbourhood that is connected if (connectivity.HasFlag(TileConnection.Top)) { path.AddRectangle(new Rectangle(centerRect.Left, fullRect.Top, centerRect.Width, centerRect.Top - fullRect.Top)); } if (connectivity.HasFlag(TileConnection.Bottom)) { path.AddRectangle(new Rectangle(centerRect.Left, centerRect.Bottom, centerRect.Width, fullRect.Bottom - centerRect.Bottom)); } if (connectivity.HasFlag(TileConnection.Left)) { path.AddRectangle(new Rectangle(fullRect.Left, centerRect.Top, centerRect.Left - fullRect.Left, centerRect.Height)); } if (connectivity.HasFlag(TileConnection.Right)) { path.AddRectangle(new Rectangle(centerRect.Right, centerRect.Top, fullRect.Right - centerRect.Right, centerRect.Height)); } // Add rects for the corners of the connected 8-neighbourhood if (connectivity.HasFlag(TileConnection.TopLeft)) { if (connectivity.HasFlag(TileConnection.Top) && !connectivity.HasFlag(TileConnection.Left)) { path.AddPolygon(new Point[] { new Point(fullRect.Left, fullRect.Top), new Point(centerRect.Left, fullRect.Top), new Point(centerRect.Left, centerRect.Top), }); } else if (!connectivity.HasFlag(TileConnection.Top) && connectivity.HasFlag(TileConnection.Left)) { path.AddPolygon(new Point[] { new Point(fullRect.Left, fullRect.Top), new Point(fullRect.Left, centerRect.Top), new Point(centerRect.Left, centerRect.Top), }); } else { path.AddRectangle(new Rectangle(fullRect.Left, fullRect.Top, centerRect.Left - fullRect.Left, centerRect.Top - fullRect.Top)); } } if (connectivity.HasFlag(TileConnection.TopRight)) { if (connectivity.HasFlag(TileConnection.Top) && !connectivity.HasFlag(TileConnection.Right)) { path.AddPolygon(new Point[] { new Point(fullRect.Right, fullRect.Top), new Point(centerRect.Right, fullRect.Top), new Point(centerRect.Right, centerRect.Top), }); } else if (!connectivity.HasFlag(TileConnection.Top) && connectivity.HasFlag(TileConnection.Right)) { path.AddPolygon(new Point[] { new Point(fullRect.Right, fullRect.Top), new Point(fullRect.Right, centerRect.Top), new Point(centerRect.Right, centerRect.Top), }); } else { path.AddRectangle(new Rectangle(centerRect.Right, fullRect.Top, fullRect.Right - centerRect.Right, centerRect.Top - fullRect.Top)); } } if (connectivity.HasFlag(TileConnection.BottomRight)) { if (connectivity.HasFlag(TileConnection.Bottom) && !connectivity.HasFlag(TileConnection.Right)) { path.AddPolygon(new Point[] { new Point(fullRect.Right, fullRect.Bottom), new Point(centerRect.Right, fullRect.Bottom), new Point(centerRect.Right, centerRect.Bottom), }); } else if (!connectivity.HasFlag(TileConnection.Bottom) && connectivity.HasFlag(TileConnection.Right)) { path.AddPolygon(new Point[] { new Point(fullRect.Right, fullRect.Bottom), new Point(fullRect.Right, centerRect.Bottom), new Point(centerRect.Right, centerRect.Bottom), }); } else { path.AddRectangle(new Rectangle(centerRect.Right, centerRect.Bottom, fullRect.Right - centerRect.Right, fullRect.Bottom - centerRect.Bottom)); } } if (connectivity.HasFlag(TileConnection.BottomLeft)) { if (connectivity.HasFlag(TileConnection.Bottom) && !connectivity.HasFlag(TileConnection.Left)) { path.AddPolygon(new Point[] { new Point(fullRect.Left, fullRect.Bottom), new Point(centerRect.Left, fullRect.Bottom), new Point(centerRect.Left, centerRect.Bottom), }); } else if (!connectivity.HasFlag(TileConnection.Bottom) && connectivity.HasFlag(TileConnection.Left)) { path.AddPolygon(new Point[] { new Point(fullRect.Left, fullRect.Bottom), new Point(fullRect.Left, centerRect.Bottom), new Point(centerRect.Left, centerRect.Bottom), }); } else { path.AddRectangle(new Rectangle(fullRect.Left, centerRect.Bottom, centerRect.Left - fullRect.Left, fullRect.Bottom - centerRect.Bottom)); } } }
// Create the corresponding GraphicsPath for the shape, and apply // it to the control by setting the Region property. private void RefreshPath() { path = new GraphicsPath(); patje = new GraphicsPath(); //switch (shape) //{ // case ShapeType.PosRectangle: path.AddRectangle(this.ClientRectangle); patje.AddString("POS1", new FontFamily("Arial"), (int)FontStyle.Regular, 10, new Point(4, 7), StringFormat.GenericDefault); // break; // case ShapeType.Ellipse: // path.AddEllipse(this.ClientRectangle); // break; // case ShapeType.Triangle: // Point pt1 = new Point(this.Width / 2, 0); // Point pt2 = new Point(0, this.Height); // Point pt3 = new Point(this.Width, this.Height); // path.AddPolygon(new Point[] { pt1, pt2, pt3 }); // break; //} this.Region = new Region(path); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { int intRate = 0; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Color UseFillColor = new Color(); Color UseBorderColor = new Color(); GraphicsPath ShapePath = new GraphicsPath(); float ptx; float pty; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; pty = (this.Height - (RadiusOuter * 2)) / 2; intRate = 0; while (!(intRate == MaxRating)) { ptx = intRate * (RadiusOuter * 2 + ShapeGap) + Padding.Left + (ShapeGap / 2); if (PaintRating > intRate) { if (!IsPainting & HighlightRateFill & (PaintRating != intRate + 1)) { UseFillColor = ShapeColorHover; UseBorderColor = ShapeBorderHoverColor; } else if (IsPainting & HighlightRateHover & (PaintRating == intRate + 1)) { UseFillColor = ShapeColorFill; UseBorderColor = ShapeBorderFilledColor; } else { UseFillColor = PaintColor; UseBorderColor = PaintBorderColor; } } else { UseFillColor = ShapeColorEmpty; UseBorderColor = ShapeBorderEmptyColor; } ShapePath.Reset(); Point[] pts; switch (Shape) { case eShape.Star: ShapePath = DrawStar(ptx, pty); break; case eShape.Heart: ShapePath = DrawHeart(ptx, pty); break; case eShape.Square: ShapePath.AddRectangle(new Rectangle((int)ptx, (int)pty, (int)(RadiusOuter * 2), (int)(RadiusOuter * 2))); break; case eShape.Circle: ShapePath.AddEllipse(ptx, pty, RadiusOuter * 2, RadiusOuter * 2); break; case eShape.Diamond: pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter)), new Point((int)(ptx + RadiusOuter), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter)) }; ShapePath.AddPolygon(pts); break; case eShape.Triangle: pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter * 2)) }; ShapePath.AddPolygon(pts); break; } e.Graphics.FillPath(new SolidBrush(UseFillColor), ShapePath); e.Graphics.DrawPath(new Pen(UseBorderColor, ShapeBorderWidth), ShapePath); if (ShapeNumberShow != eShapeNumberShow.None) { if (ShapeNumberShow == eShapeNumberShow.All | (ShapeNumberShow == eShapeNumberShow.RateOnly & PaintRating == intRate + 1)) { e.Graphics.DrawString((intRate + 1).ToString(), ShapeNumberFont, new SolidBrush(ShapeNumberColor), new RectangleF(ShapeNumberIndent.X + ptx, ShapeNumberIndent.Y + pty, RadiusOuter * 2, RadiusOuter * 2), sf); } } intRate += 1; } if (LabelShow) { int R_x = (int)(((RadiusOuter * 2) * (MaxRating)) + LabelIndent + ((ShapeGap) * MaxRating) + Padding.Left); if (IsPainting) { RateLabel.Text = GetLabelText(LabelTypeHover); } else { RateLabel.Text = GetLabelText(LabelTypeText); } RateLabel.Width = (this.Width - R_x); RateLabel.Height = (this.Height); RateLabel.Location = new Point(R_x, 0); } }
public void NextSubpath_NextMarker() { GraphicsPath path = new GraphicsPath(); path.AddLine(10, 10, 50, 50); // figure #1 path.AddLine(50, 50, 80, 80); path.AddLine(90, 90, 100, 100); path.SetMarkers(); // marker #1 path.AddLine(150, 150, 180, 180); path.SetMarkers(); // marker #2 path.StartFigure(); // figure #2 path.SetMarkers(); // marker #3 is actually marker #2 path.AddRectangle(new Rectangle(200, 200, 200, 200)); path.SetMarkers(); // marker #4 path.AddLine(150, 150, 180, 180); path.StartFigure(); // figure #3 path.AddBezier(400, 400, 500, 500, 600, 600, 700, 700); path.AddBezier(450, 450, 550, 550, 650, 650, 750, 750); GraphicsPathIterator iterator = new GraphicsPathIterator(path); int start; int end; bool isClosed; int count = iterator.NextMarker(out start, out end); // marker #1 Assert.AreEqual(5, count); Assert.AreEqual(0, start); Assert.AreEqual(4, end); count = iterator.NextSubpath(out start, out end, out isClosed); // figure #1 Assert.AreEqual(7, count); Assert.AreEqual(0, start); Assert.AreEqual(6, end); Assert.AreEqual(false, isClosed); count = iterator.NextMarker(out start, out end); // marker #2 (and #3) Assert.AreEqual(2, count); Assert.AreEqual(5, start); Assert.AreEqual(6, end); count = iterator.NextSubpath(out start, out end, out isClosed); // figure #2 Assert.AreEqual(4, count); Assert.AreEqual(7, start); Assert.AreEqual(10, end); Assert.AreEqual(true, isClosed); count = iterator.NextSubpath(out start, out end, out isClosed); // figure #3 Assert.AreEqual(2, count); Assert.AreEqual(11, start); Assert.AreEqual(12, end); Assert.AreEqual(false, isClosed); count = iterator.NextMarker(out start, out end); // marker #5 (end) Assert.AreEqual(4, count); Assert.AreEqual(7, start); Assert.AreEqual(10, end); count = iterator.NextMarker(out start, out end); // marker #5 (end) Assert.AreEqual(10, count); Assert.AreEqual(11, start); Assert.AreEqual(20, end); // we dont want to be bug compliant with .net /* * count = iterator.NextMarker (out start,out end); // no more markers * Assert.AreEqual (0, count); * Assert.AreEqual (11, start); * Assert.AreEqual (20, end); */ count = iterator.NextSubpath(out start, out end, out isClosed); // figure #4 Assert.AreEqual(8, count); Assert.AreEqual(13, start); Assert.AreEqual(20, end); Assert.AreEqual(false, isClosed); // we dont want to be bug compliant with .net /* * count = iterator.NextMarker (out start,out end); // no more markers * Assert.AreEqual (0, count); * Assert.AreEqual (13, start); * Assert.AreEqual (20, end); */ count = iterator.NextSubpath(out start, out end, out isClosed); // no more figures Assert.AreEqual(0, count); Assert.AreEqual(0, start); Assert.AreEqual(0, end); Assert.AreEqual(true, isClosed); count = iterator.NextMarker(out start, out end); // no more markers Assert.AreEqual(0, count); Assert.AreEqual(0, start); Assert.AreEqual(0, end); }
public ColorWheel(Rectangle colorRectangle, Rectangle brightnessRectangle, Rectangle selectedColorRectangle) { // Caller must provide locations for color wheel // (colorRectangle), brightness "strip" (brightnessRectangle) // and location to display selected color (selectedColorRectangle). using (GraphicsPath path = new GraphicsPath()) { // Store away locations for later use. this.colorRectangle = colorRectangle; this.brightnessRectangle = brightnessRectangle; this.selectedColorRectangle = selectedColorRectangle; // Calculate the center of the circle. // Start with the location, then offset // the point by the radius. // Use the smaller of the width and height of // the colorRectangle value. this.radius = (int)Math.Min(colorRectangle.Width, colorRectangle.Height) / 2; this.centerPoint = colorRectangle.Location; this.centerPoint.Offset(radius, radius); // Start the pointer in the center. this.colorPoint = this.centerPoint; // Create a region corresponding to the color circle. // Code uses this later to determine if a specified // point is within the region, using the IsVisible // method. path.AddEllipse(colorRectangle); colorRegion = new Region(path); // set { the range for the brightness selector. this.brightnessMin = this.brightnessRectangle.Top; this.brightnessMax = this.brightnessRectangle.Bottom; // Create a region corresponding to the // brightness rectangle, with a little extra // "breathing room". path.AddRectangle(new Rectangle(brightnessRectangle.Left, brightnessRectangle.Top - 10, brightnessRectangle.Width + 10, brightnessRectangle.Height + 20)); // Create region corresponding to brightness // rectangle. Later code uses this to // determine if a specified point is within // the region, using the IsVisible method. brightnessRegion = new Region(path); // Set the location for the brightness indicator "marker". // Also calculate the scaling factor, scaling the height // to be between 0 and 255. brightnessX = brightnessRectangle.Left + brightnessRectangle.Width; brightnessScaling = (double)255 / (brightnessMax - brightnessMin); // Calculate the location of the brightness // pointer. Assume it's at the highest position. brightnessPoint = new Point(brightnessX, brightnessMax); // Create the bitmap that contains the circular gradient. CreateGradient(); } }
public ColorWheel(Rectangle colorRectangle, Rectangle brightnessRectangle, Rectangle selectedColorRectangle) { // Caller must provide locations for color wheel // (colorRectangle), brightness "strip" (brightnessRectangle) // and location to display selected color (selectedColorRectangle). using (GraphicsPath path = new GraphicsPath()) { // Store away locations for later use. this.colorRectangle = colorRectangle; this.brightnessRectangle = brightnessRectangle; this.selectedColorRectangle = selectedColorRectangle; //this.selectedColor = Color.FromArgb(RGB.Alpha, RGB.Red, RGB.Green, RGB.Blue); // Calculate the center of the circle. // Start with the location, then offset // the point by the radius. // Use the smaller of the width and height of // the colorRectangle value. this.radius = (int)Math.Min(colorRectangle.Width, colorRectangle.Height) / 2; this.centerPoint = colorRectangle.Location; this.centerPoint.Offset(radius, radius); // Start the pointer in the center. this.colorPoint = this.centerPoint; // Create a region corresponding to the color circle. // Code uses this later to determine if a specified // point is within the region, using the IsVisible // method. path.AddEllipse(colorRectangle); colorRegion = new Region(path); // set { the range for the brightness selector. this.brightnessMin = this.brightnessRectangle.Top; this.brightnessMax = this.brightnessRectangle.Bottom; // Create a region corresponding to the // brightness rectangle, with a little extra // "breathing room". path.AddRectangle(new Rectangle(brightnessRectangle.Left, brightnessRectangle.Top - 10, brightnessRectangle.Width + 10, brightnessRectangle.Height + 20)); // Create region corresponding to brightness // rectangle. Later code uses this to // determine if a specified point is within // the region, using the IsVisible method. brightnessRegion = new Region(path); // Set the location for the brightness indicator "marker". // Also calculate the scaling factor, scaling the height // to be between 0 and 255. brightnessX = brightnessRectangle.Left + brightnessRectangle.Width; brightnessScaling = (double)255 / (brightnessMax - brightnessMin); // Calculate the location of the brightness // pointer. Assume it's at the highest position. brightnessPoint = new Point(brightnessX, brightnessMax); // Create the bitmap that contains the circular gradient. CreateGradient(); } }
protected virtual void AddShapePath(GraphicsPath graphicsPath, Rectangle rect) { graphicsPath.AddRectangle(rect); }
public static GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners corners, WhichHalf half) { if (radius <= 0) { GraphicsPath rectp = new GraphicsPath(); rectp.AddRectangle(new Rectangle(x, y, width, height)); return(rectp); } int dia = radius * 2; Rectangle TLarc = new Rectangle(x, y, dia, dia); Rectangle TRarc = new Rectangle(x + width - dia - 1, y, dia, dia); Rectangle BRarc = new Rectangle(x + width - dia - 1, y + height - dia - 1, dia, dia); Rectangle BLarc = new Rectangle(x, y + height - dia - 1, dia, dia); Rectangle TLsquare = new Rectangle(x, y, radius, radius); Rectangle TRsquare = new Rectangle(x + width - radius, y, radius, radius); Rectangle BRsquare = new Rectangle(x + width - radius, y + height - radius, radius, radius); Rectangle BLsquare = new Rectangle(x, y + height - radius, radius, radius); GraphicsPath p = new GraphicsPath(); p.StartFigure(); if (half == WhichHalf.Both || half == WhichHalf.TopLeft) { if (corners.HasFlag(RectangleCorners.BottomLeft)) { p.AddArc(BLarc, 135, 45); } else { p.AddLine(BLsquare.Left, BLsquare.Bottom, BLsquare.Left, BLsquare.Top); } p.AddLine(BLsquare.Left, BLsquare.Top - 1, TLsquare.Left, TLsquare.Bottom + 1); if (corners.HasFlag(RectangleCorners.TopLeft)) { p.AddArc(TLarc, 180, 90); } else { Corner(p, TLsquare.Left, TLsquare.Bottom, TLsquare.Left, TLsquare.Top, TLsquare.Right, TLsquare.Top); } p.AddLine(TLsquare.Right + 1, TLsquare.Top, TRsquare.Left - 1, TRsquare.Top); if (corners.HasFlag(RectangleCorners.TopRight)) { p.AddArc(TRarc, -90, 45); } } if (half == WhichHalf.Both || half == WhichHalf.BottomRight) { if (corners.HasFlag(RectangleCorners.TopRight)) { p.AddArc(TRarc, -45, 45); } else { p.AddLine(TRsquare.Right, TRsquare.Top, TRsquare.Right, TRsquare.Bottom); } p.AddLine(TRsquare.Right, TRsquare.Bottom + 1, BRsquare.Right, BRsquare.Top - 1); if (corners.HasFlag(RectangleCorners.BottomRight)) { p.AddArc(BRarc, 0, 90); } else { Corner(p, BRsquare.Right, BRsquare.Top, BRsquare.Right, BRsquare.Bottom, BRsquare.Left, BRsquare.Bottom); } p.AddLine(BRsquare.Left - 1, BRsquare.Bottom, BLsquare.Right + 1, BLsquare.Bottom); if (corners.HasFlag(RectangleCorners.BottomLeft)) { p.AddArc(BLarc, 90, 45); } else { p.AddLine(BLsquare.Right, BLsquare.Bottom, BLsquare.Left, BLsquare.Bottom); } } return(p); }
/// <summary> /// /// </summary> /// <param name="rc"></param> /// <returns></returns> private GraphicsPath BuildTitleBarShape( Rectangle rc ) { GraphicsPath e = new GraphicsPath(); switch (m_eTitleBarType) { case XTitleBarType.Rounded: e.AddArc( rc.Left, rc.Top, rc.Height, rc.Height, 90, 180); e.AddLine( rc.Left + rc.Height / 2, rc.Top, rc.Right, rc.Top ); e.AddArc( rc.Right, rc.Top, rc.Height, rc.Height, -90, 180); e.AddLine( rc.Right, rc.Bottom, rc.Left + rc.Height / 2, rc.Bottom); break; case XTitleBarType.Angular: e.AddLine( rc.Left, rc.Bottom, rc.Left + 20, rc.Top); e.AddLine( rc.Left + 20, rc.Top, rc.Right, rc.Top); e.AddLine( rc.Right, rc.Top, rc.Right - 20, rc.Bottom ); e.AddLine( rc.Right - 20, rc.Bottom, rc.Left, rc.Bottom ); break; case XTitleBarType.Rectangular: e.AddRectangle(rc); break; } return(e); }
GraphicsPath CreatePath() { var newPath = new GraphicsPath(); var start = StartFigures; var close = CloseFigures; // connected segments newPath.MoveTo(10, 10); newPath.LineTo(20, 90); newPath.LineTo(10, 60); newPath.LineTo(90, 80); newPath.LineTo(60, 30); if (close && start) { newPath.CloseFigure(); } if (start) { newPath.StartFigure(); } newPath.AddArc(100, 0, 100, 50, 200, -160); if (close && start) { newPath.CloseFigure(); } if (start) { newPath.StartFigure(); } newPath.AddBezier(new PointF(200, 10), new PointF(285, 20), new PointF(210, 85), new PointF(300, 90)); if (close && start) { newPath.CloseFigure(); } if (start) { newPath.StartFigure(); } newPath.AddCurve(new PointF(310, 90), new PointF(390, 90), new PointF(390, 10), new PointF(310, 10)); if (close && start) { newPath.CloseFigure(); } if (start) { newPath.StartFigure(); } newPath.AddLine(410, 10, 410, 90); if (close && start) { newPath.CloseFigure(); } if (start) { newPath.StartFigure(); } newPath.AddLines(new PointF(420, 10), new PointF(420, 90)); if (close && start) { newPath.CloseFigure(); } if (start) { newPath.StartFigure(); } newPath.AddLines(new PointF(430, 10), new PointF(430, 90)); if (close) { newPath.CloseFigure(); } // separate segments if (start) { newPath.StartFigure(); } newPath.AddEllipse(100, 100, 100, 45); if (close) { newPath.CloseFigure(); } if (start) { newPath.StartFigure(); } newPath.AddRectangle(10, 110, 80, 80); if (close) { newPath.CloseFigure(); } // at the end, draw a line so we can potentially connect to parent path if (start) { newPath.StartFigure(); } newPath.AddLines(new PointF(440, 10), new PointF(440, 90)); if (close) { newPath.CloseFigure(); } return(newPath); }
public override void Draw(Graphics g) { Color bcolor = Color.White; Color fColor1 = Color.White; Color fColor2 = Color.White; try { if (this.Visible) { if (Common.Blinking && shapeoutline.BoarderBlinking) { bcolor = shapeoutline.BoarderColor2; } else { bcolor = shapeoutline.BoarderColor1; } Pen pen = new Pen(bcolor, shapeoutline.BoarderWidth); pen.DashStyle = shapeoutline.BoarderDashStyle; GraphicsPath gp = new GraphicsPath(); switch (shapefill.FillType) { case FillTypePatern.Transparent: break; case FillTypePatern.Solid: if (Common.Blinking && shapefill.Blinking) { fColor1 = shapefill.FillColor12; } else { fColor1 = shapefill.FillColor11; } break; case FillTypePatern.Hatched: if (Common.Blinking && shapefill.Blinking) { fColor1 = Color.Transparent; } else { fColor1 = shapefill.FillColor11; } break; case FillTypePatern.Gradient: if (Common.Blinking && shapefill.Blinking) { fColor1 = Color.Transparent; fColor2 = Color.Transparent; } else { fColor1 = shapefill.FillColor11; fColor2 = shapefill.FillColor21; } break; } if ((RoundnessX == 0) && (RoundnessY == 0)) { gp.AddRectangle(rectangle); } else { if (RoundnessX == 0) { RoundnessX = 1; } if (RoundnessY == 0) { RoundnessY = 1; } if (2 * RoundnessY > rectangle.Height) { RoundnessY = rectangle.Height / 2; } if (2 * RoundnessX > rectangle.Width) { RoundnessX = rectangle.Width / 2; } gp.AddLine(rectangle.Left + RoundnessX, rectangle.Top, rectangle.Left + rectangle.Width - (RoundnessX), rectangle.Top); // Line gp.AddArc(rectangle.Left + rectangle.Width - (RoundnessX * 2), rectangle.Top, RoundnessX * 2, RoundnessY * 2, 270, 90); // Corner gp.AddLine(rectangle.Left + rectangle.Width, rectangle.Top + RoundnessY, rectangle.Left + rectangle.Width, rectangle.Top + rectangle.Height - (RoundnessY)); // Line gp.AddArc(rectangle.Left + rectangle.Width - (RoundnessX * 2), rectangle.Top + rectangle.Height - (RoundnessY * 2), RoundnessX * 2, RoundnessY * 2, 0, 90); // Corner gp.AddLine(rectangle.Left + rectangle.Width - (RoundnessX), rectangle.Top + rectangle.Height, rectangle.Left + RoundnessX, rectangle.Top + rectangle.Height); // Line gp.AddArc(rectangle.Left, rectangle.Top + rectangle.Height - (RoundnessY * 2), RoundnessX * 2, RoundnessY * 2, 90, 90); // Corner gp.AddLine(rectangle.Left, rectangle.Top + rectangle.Height - (RoundnessY), rectangle.Left, rectangle.Top + RoundnessY); // Line gp.AddArc(rectangle.Left, rectangle.Top, RoundnessX * 2, RoundnessY * 2, 180, 90); // Corner } switch (shapefill.FillType) { case FillTypePatern.Transparent: if (shapeoutline.BoarderWidth != 0) { g.DrawPath(pen, gp); } pen.Dispose(); gp.Dispose(); break; case FillTypePatern.Solid: Brush b = new SolidBrush(fColor1); g.FillPath(b, gp); if (shapeoutline.BoarderWidth != 0) { g.DrawPath(pen, gp); } gp.Dispose(); pen.Dispose(); b.Dispose(); break; case FillTypePatern.Hatched: using (HatchBrush hatchbrush = new HatchBrush(shapefill.hatchStyle, fColor1, Color.Transparent)) { if (shapeoutline.BoarderWidth != 0) { g.DrawPath(pen, gp); } g.FillPath(hatchbrush, gp); } gp.Dispose(); pen.Dispose(); //hatchbrush.Dispose(); break; case FillTypePatern.Gradient: int x1, x2, y1, y2; x1 = rectangle.X; y1 = rectangle.Y; x2 = rectangle.Right; y2 = rectangle.Bottom; Point pt1 = new Point(); Point pt2 = new Point(); switch (shapefill.Fillgradienttype) { case FillGradientType.Buttom2Top: pt1 = new Point(x1, y2); pt2 = new Point(x1, y1); break; case FillGradientType.Left2Right: pt1 = new Point(x1, y1); pt2 = new Point(x2, y1); break; case FillGradientType.Top2Buttom: pt1 = new Point(x1, y1); pt2 = new Point(x1, y2); break; case FillGradientType.Right2Left: pt1 = new Point(x2, y1); pt2 = new Point(x1, y1); break; case FillGradientType.NE2SW: pt1 = new Point(x2, y1); pt2 = new Point(x1, y2); break; case FillGradientType.NW2SE: pt1 = new Point(x1, y1); pt2 = new Point(x2, y2); break; case FillGradientType.SE2NW: pt1 = new Point(x2, y2); pt2 = new Point(x1, y1); break; case FillGradientType.SW2NE: pt1 = new Point(x1, y2); pt2 = new Point(x2, y1); break; case FillGradientType.FromHCenter: pt1 = new Point(x1, y1); pt2 = new Point(x1, y2); break; case FillGradientType.FromVCenter: pt1 = new Point(x1, y1); pt2 = new Point(x2, y1); break; case FillGradientType.ToHCenter: pt1 = new Point(x1, y1); pt2 = new Point(x1, y2); break; case FillGradientType.ToVCenter: pt1 = new Point(x1, y1); pt2 = new Point(x2, y1); break; } switch (shapefill.Fillgradienttype) { case FillGradientType.Buttom2Top: case FillGradientType.Left2Right: case FillGradientType.Top2Buttom: case FillGradientType.Right2Left: case FillGradientType.NE2SW: case FillGradientType.NW2SE: case FillGradientType.SE2NW: case FillGradientType.SW2NE: using (LinearGradientBrush br = new LinearGradientBrush(pt1, pt2, fColor1, fColor2)) { g.FillPath(br, gp); if (shapeoutline.BoarderWidth != 0) { g.DrawPath(pen, gp); } } break; case FillGradientType.FromHCenter: case FillGradientType.FromVCenter: using (LinearGradientBrush br = new LinearGradientBrush(pt1, pt2, fColor1, fColor2)) { ColorBlend cb = new ColorBlend(); cb.Colors = new Color[] { fColor2, fColor1, fColor2 }; cb.Positions = new float[] { 0, 0.5F, 1 }; br.InterpolationColors = cb; g.FillPath(br, gp); if (shapeoutline.BoarderWidth != 0) { g.DrawPath(pen, gp); } } break; case FillGradientType.ToHCenter: case FillGradientType.ToVCenter: using (LinearGradientBrush br = new LinearGradientBrush(pt1, pt2, fColor1, fColor2)) { ColorBlend cb = new ColorBlend(); cb.Colors = new Color[] { fColor1, fColor2, fColor1 }; cb.Positions = new float[] { 0, 0.5F, 1 }; br.InterpolationColors = cb; g.FillPath(br, gp); if (shapeoutline.BoarderWidth != 0) { g.DrawPath(pen, gp); } } break; } gp.Dispose(); pen.Dispose(); break; } } } catch (Exception e) { MessageBox.Show(e.Message); } //Trace.WriteLine("Draw rectangle.Left=" + rectangle.Left.ToString() + " rectangle.Top=" + rectangle.Top.ToString() + " rectangle.Width=" + rectangle.Width.ToString() + " rectangle.Height=" + rectangle.Height.ToString()); }
private void RenderItemBackgroundPressed(System.Windows.Forms.ToolStripItemRenderEventArgs e) { if (Theme.Standard.Style == RibbonOrbStyle.Office_2013) { Rectangle rectBorder = new Rectangle(1, 1, e.Item.Width - 1, e.Item.Height - 1); Rectangle rect = new Rectangle(2, 2, e.Item.Width - 2, e.Item.Height - 2); using (SolidBrush b = new SolidBrush(Theme.Standard.RendererColorTable.ButtonPressed_2013)) { using (SolidBrush sb = new SolidBrush(Theme.Standard.RendererColorTable.ButtonBorderOut)) { e.Graphics.FillRectangle(sb, rectBorder); } e.Graphics.FillRectangle(b, rect); } } else { Rectangle rectBorder = new Rectangle(1, 1, e.Item.Width - 1, e.Item.Height - 1); Rectangle rect = new Rectangle(2, 2, e.Item.Width - 2, e.Item.Height - 2); Rectangle innerR = Rectangle.FromLTRB(1, 1, e.Item.Width - 2, e.Item.Height - 2); Rectangle glossyR = Rectangle.FromLTRB(1, 1, e.Item.Width - 2, 1 + Convert.ToInt32((double)e.Item.Bounds.Height * .36)); using (SolidBrush brus = new SolidBrush(Theme.Standard.RendererColorTable.ButtonPressedBgOut)) { e.Graphics.FillRectangle(brus, rectBorder); } //Border using (Pen p = new Pen(Theme.Standard.RendererColorTable.ButtonPressedBorderOut)) { e.Graphics.DrawRectangle(p, rectBorder); } //Inner border Rectangle RoundedRect = Rectangle.Round(innerR); using (Pen p = new Pen(Theme.Standard.RendererColorTable.ButtonPressedBorderIn)) { e.Graphics.DrawRectangle(p, RoundedRect); } #region Main Bg using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(new Rectangle(1, 1, e.Item.Width, e.Item.Height * 2)); path.CloseFigure(); using (PathGradientBrush gradient = new PathGradientBrush(path)) { gradient.WrapMode = WrapMode.Clamp; gradient.CenterPoint = new PointF(Convert.ToSingle(1 + e.Item.Width / 2), Convert.ToSingle(e.Item.Bounds.Height)); gradient.CenterColor = Theme.Standard.RendererColorTable.ButtonPressedBgCenter; gradient.SurroundColors = new Color[] { Theme.Standard.RendererColorTable.ButtonPressedBgOut }; Blend blend = new Blend(3); blend.Factors = new float[] { 0f, 0.8f, 0f }; blend.Positions = new float[] { 0f, 0.30f, 1f }; Region lastClip = e.Graphics.Clip; Region newClip = new Region(rectBorder); newClip.Intersect(lastClip); e.Graphics.SetClip(newClip.GetBounds(e.Graphics)); e.Graphics.FillPath(gradient, path); e.Graphics.Clip = lastClip; } } #endregion //Glossy effect using (GraphicsPath path = new GraphicsPath()) { path.AddRectangle(Rectangle.Round(glossyR)); using (LinearGradientBrush b = new LinearGradientBrush(glossyR, Theme.Standard.RendererColorTable.ButtonPressedGlossyNorth, Theme.Standard.RendererColorTable.ButtonPressedGlossySouth, 90)) { b.WrapMode = WrapMode.TileFlipXY; e.Graphics.FillPath(b, path); } } } }
private void VisualToolTip_Draw(object sender, DrawToolTipEventArgs e) { Graphics graphics = e.Graphics; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.TextRenderingHint = _textRendererHint; graphics.FillRectangle(new SolidBrush(_background), e.Bounds); if (_border.Visible) { Rectangle boxRectangle = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1); GraphicsPath borderPath = new GraphicsPath(); borderPath.AddRectangle(boxRectangle); graphics.DrawPath(new Pen(_border.Color, _border.Thickness), borderPath); } if ((_textShadow && (_toolTipType == ToolTipType.Text)) || (_textShadow && (_toolTipType == ToolTipType.Default))) { // Draw shadow text graphics.DrawString(_text, new Font(Font, FontStyle.Regular), Brushes.Silver, new PointF(_textPoint.X + 1, _textPoint.Y + 1)); } switch (_toolTipType) { case ToolTipType.Default: { // Draw the title graphics.DrawString(_title, _titleFont, new SolidBrush(_titleColor), new PointF(_titlePoint.X, _titlePoint.Y)); // Draw the separator graphics.DrawLine(new Pen(_lineColor), _separator.X, _separator.Y, _separator.Width, _separator.Y); // Draw the text graphics.DrawString(_text, Font, new SolidBrush(_foreColor), new PointF(_textPoint.X, _textPoint.Y)); if (Icon != null) { // Update point _iconRectangle.Location = _iconPoint; // Draw icon border if (_iconBorder) { graphics.DrawPath(new Pen(_border.Color), _iconGraphicsPath); } // Draw icon graphics.DrawImage(Icon, _iconRectangle); } break; } case ToolTipType.Image: { if (Icon != null) { // Update point _iconRectangle.Location = _iconPoint; // Draw icon border if (_iconBorder) { graphics.DrawPath(new Pen(_border.Color), _iconGraphicsPath); } // Draw icon graphics.DrawImage(Icon, _iconRectangle); } break; } case ToolTipType.Text: { // Draw the text graphics.DrawString(_text, Font, new SolidBrush(_foreColor), new PointF(_textPoint.X, _textPoint.Y)); break; } } }
public Form1() { InitializeComponent(); gp.AddEllipse(new Rectangle(x - r, y - r, 2 * r, 2 * r)); gp.AddRectangle(new Rectangle(x + r, y + r, r, r)); }
// </snippet1> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.Enumerate(System.Drawing.PointF[]@,System.Byte[]@) // <snippet2> public void EnumerateExample(PaintEventArgs e) { GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, and arrays of // the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing the array of points on the left // side of the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the set of points and types and types to the left side // of the screen. e.Graphics.DrawString("Original Data", myFont, myBrush, 20, j); j += 20; for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator for myPath. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); myPathIterator.Rewind(); PointF[] points = new PointF[myPathIterator.Count]; byte[] types = new byte[myPathIterator.Count]; int numPoints = myPathIterator.Enumerate(ref points, ref types); // Draw the set of copied points and types to the screen. j = 20; e.Graphics.DrawString("Copied Data", myFont, myBrush, 200, j); j += 20; for (i = 0; i < points.Length; i++) { e.Graphics.DrawString("Point: " + i + ", " + "Value: " + points[i].ToString() + ", " + "Type: " + types[i].ToString(), myFont, myBrush, 200, j); j += 20; } }
/// <summary> /// Draws labels in a specified rectangle. /// </summary> /// <param name="g">The graphics object to draw to.</param> /// <param name="labelText">The label text to draw.</param> /// <param name="labelBounds">The rectangle of the label.</param> /// <param name="symb">the Label Symbolizer to use when drawing the label.</param> /// <param name="feature">Feature to draw.</param> /// <param name="angle">Angle in degree the label gets rotated by.</param> private static void DrawLabel(Graphics g, string labelText, RectangleF labelBounds, ILabelSymbolizer symb, IFeature feature, float angle) { // Sets up the brushes and such for the labeling Font textFont = CacheList.GetFont(symb); var format = new StringFormat { Alignment = symb.Alignment }; // Text graphics path var gp = new GraphicsPath(); gp.AddString(labelText, textFont.FontFamily, (int)textFont.Style, textFont.SizeInPoints * 96F / 72F, labelBounds, format); // Rotate text RotateAt(g, labelBounds.X, labelBounds.Y, angle); // Draws the text outline if (symb.BackColorEnabled && symb.BackColor != Color.Transparent) { var backBrush = CacheList.GetSolidBrush(symb.BackColor); if (symb.FontColor == Color.Transparent) { using (var backgroundGp = new GraphicsPath()) { backgroundGp.AddRectangle(labelBounds); backgroundGp.FillMode = FillMode.Alternate; backgroundGp.AddPath(gp, true); g.FillPath(backBrush, backgroundGp); } } else { g.FillRectangle(backBrush, labelBounds); } } // Draws the border if its enabled if (symb.BorderVisible && symb.BorderColor != Color.Transparent) { var borderPen = CacheList.GetPen(symb.BorderColor); g.DrawRectangle(borderPen, labelBounds.X, labelBounds.Y, labelBounds.Width, labelBounds.Height); } // Draws the drop shadow if (symb.DropShadowEnabled && symb.DropShadowColor != Color.Transparent) { var shadowBrush = CacheList.GetSolidBrush(symb.DropShadowColor); var gpTrans = new Matrix(); gpTrans.Translate(symb.DropShadowPixelOffset.X, symb.DropShadowPixelOffset.Y); gp.Transform(gpTrans); g.FillPath(shadowBrush, gp); gpTrans = new Matrix(); gpTrans.Translate(-symb.DropShadowPixelOffset.X, -symb.DropShadowPixelOffset.Y); gp.Transform(gpTrans); gpTrans.Dispose(); } // Draws the text halo if (symb.HaloEnabled && symb.HaloColor != Color.Transparent) { using (var haloPen = new Pen(symb.HaloColor) { Width = 2, Alignment = PenAlignment.Outset }) g.DrawPath(haloPen, gp); } // Draws the text if its not transparent if (symb.FontColor != Color.Transparent) { var foreBrush = CacheList.GetSolidBrush(symb.FontColor); g.FillPath(foreBrush, gp); } gp.Dispose(); }
// </snippet3> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextMarker(System.Drawing.Drawing2D.GraphicsPath) // <snippet4> public void NextMarkerExample2(PaintEventArgs e) { // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up primitives to add to myPath. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, // and the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing all the values of the path's // points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the values for all of path points and types to // the left side of the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the iterator. myPathIterator.Rewind(); // Create a GraphicsPath to receive a section of myPath. GraphicsPath myPathSection = new GraphicsPath(); // Retrieve and list the number of points contained in // the first marker to the right side of the screen. int markerPoints; markerPoints = myPathIterator.NextMarker(myPathSection); e.Graphics.DrawString("Marker: 1" + " Num Points: " + markerPoints.ToString(), myFont, myBrush, 200, 20); }
protected override void OnPaint(PaintEventArgs e) { Helpers.B = new Bitmap(Width, Height); Helpers.G = Graphics.FromImage(Helpers.B); W = Width - 1; H = Height - 1; Rectangle Base = new Rectangle(0, 24, W, H); GraphicsPath GP = new GraphicsPath(); GraphicsPath GP2 = new GraphicsPath(); GraphicsPath GP3 = new GraphicsPath(); Helpers.G.SmoothingMode = (System.Drawing.Drawing2D.SmoothingMode) 2; Helpers.G.PixelOffsetMode = (System.Drawing.Drawing2D.PixelOffsetMode) 2; Helpers.G.TextRenderingHint = (System.Drawing.Text.TextRenderingHint) 5; Helpers.G.Clear(BackColor); //-- Progress Value int iValue = Convert.ToInt32(_Value / (double)_Maximum * Width); switch (Value) { case 0: //-- Base Helpers.G.FillRectangle(new SolidBrush(_BaseColor), Base); //--Progress Helpers.G.FillRectangle(new SolidBrush(_ProgressColor), new Rectangle(0, 24, iValue - 1, H - 1)); break; case 100: //-- Base Helpers.G.FillRectangle(new SolidBrush(_BaseColor), Base); //--Progress Helpers.G.FillRectangle(new SolidBrush(_ProgressColor), new Rectangle(0, 24, iValue - 1, H - 1)); break; default: //-- Base Helpers.G.FillRectangle(new SolidBrush(_BaseColor), Base); //--Progress GP.AddRectangle(new Rectangle(0, 24, iValue - 1, H - 1)); Helpers.G.FillPath(new SolidBrush(_ProgressColor), GP); //-- Hatch Brush HatchBrush HB = new HatchBrush(HatchStyle.Plaid, _DarkerProgress, _ProgressColor); Helpers.G.FillRectangle(HB, new Rectangle(0, 24, iValue - 1, H - 1)); //-- Balloon Rectangle Balloon = new Rectangle(iValue - 18, 0, 34, 16); GP2 = Helpers.RoundRec(Balloon, 4); Helpers.G.FillPath(new SolidBrush(_BaseColor), GP2); //-- Arrow GP3 = Helpers.DrawArrow(iValue - 9, 16, true); Helpers.G.FillPath(new SolidBrush(_BaseColor), GP3); //-- Value > You can add "%" > value & "%" Helpers.G.DrawString(Value.ToString(), new Font("Segoe UI", 10), new SolidBrush(_ProgressColor), new Rectangle(iValue - 11, -2, W, H), Helpers.NearSF); break; } base.OnPaint(e); Helpers.G.Dispose(); e.Graphics.InterpolationMode = (System.Drawing.Drawing2D.InterpolationMode) 7; e.Graphics.DrawImageUnscaled(Helpers.B, 0, 0); Helpers.B.Dispose(); }
// </snippet6> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextSubpath(System.Drawing.Drawing2D.GraphicsPath,System.Boolean@) // <snippet7> public void NextSubpathExample2(PaintEventArgs e) { // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up primitives to add to myPath. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, // and the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing all of the path's // points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the values of all the path points and types to the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator for myPath. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the iterator. myPathIterator.Rewind(); // Create the GraphicsPath section. GraphicsPath myPathSection = new GraphicsPath(); // Iterate to the 3rd subpath and list the number of points therein // to the screen. int subpathPoints; bool IsClosed2; // Iterate to the third subpath. subpathPoints = myPathIterator.NextSubpath( myPathSection, out IsClosed2); subpathPoints = myPathIterator.NextSubpath( myPathSection, out IsClosed2); subpathPoints = myPathIterator.NextSubpath( myPathSection, out IsClosed2); // Write the number of subpath points to the screen. e.Graphics.DrawString("Subpath: 3" + " Num Points: " + subpathPoints.ToString(), myFont, myBrush, 200, 20); }
public virtual void NextPathType() { GraphicsPath path = new GraphicsPath(); path.AddLine(new Point(100, 100), new Point(400, 100)); path.AddBezier(100, 100, 500, 250, 100, 50, 250, 280); path.AddLine(new Point(400, 200), new Point(10, 100)); path.StartFigure(); path.SetMarkers(); path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280); path.StartFigure(); path.SetMarkers(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.SetMarkers(); path.AddLine(new Point(400, 400), new Point(400, 10)); GraphicsPathIterator iterator = new GraphicsPathIterator(path); byte pathType; int start; int end; bool isClosed; int count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(0, count); Assert.AreEqual((byte)PathPointType.Start, pathType); Assert.AreEqual(0, start); Assert.AreEqual(0, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(3, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(0, start); Assert.AreEqual(2, end); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(4, count); Assert.AreEqual((byte)PathPointType.Bezier3, pathType); Assert.AreEqual(2, start); Assert.AreEqual(5, end); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(3, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(5, start); Assert.AreEqual(7, end); // we don't want to be a bug compliant with .net /* * count = iterator.NextPathType (out pathType, out start, out end); * Assert.AreEqual (0, count); * Assert.AreEqual ((byte)PathPointType.Line, pathType); * Assert.AreEqual (5, start); * Assert.AreEqual (7, end); */ iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(4, count); Assert.AreEqual((byte)PathPointType.Bezier3, pathType); Assert.AreEqual(8, start); Assert.AreEqual(11, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(4, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(12, start); Assert.AreEqual(15, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(2, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(16, start); Assert.AreEqual(17, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(0, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(0, start); Assert.AreEqual(0, end); }
// </snippet7> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextSubpath(System.Int32@,System.Int32@,System.Boolean@) // <snippet8> private void NextSubpathExample(PaintEventArgs e) { // Create the GraphicsPath. GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, // and the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for drawing the array of // points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // Draw the set of path points and types to the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); int myStartIndex; int myEndIndex; bool myIsClosed; // get the number of Subpaths. int numSubpaths = myPathIterator.NextSubpath(myPath, out myIsClosed); numSubpaths -= 1; // Rewind the Iterator. myPathIterator.Rewind(); // List the Subpaths to the screen. j = 20; for (i = 0; i < numSubpaths; i++) { myPathIterator.NextSubpath(out myStartIndex, out myEndIndex, out myIsClosed); e.Graphics.DrawString("Subpath " + i.ToString() + ": Start: " + myStartIndex.ToString() + " End: " + myEndIndex.ToString() + " IsClosed: " + myIsClosed.ToString(), myFont, myBrush, 200, j); j += 20; } // Draw the total number of Subpaths to the screen. j += 20; e.Graphics.DrawString("Number Subpaths = " + numSubpaths.ToString(), myFont, myBrush, 200, j); }
public virtual void NextMarker_GraphicsPath() { GraphicsPath path = new GraphicsPath(); path.AddLine(new Point(100, 100), new Point(400, 100)); path.AddLine(new Point(400, 200), new Point(10, 100)); path.StartFigure(); path.SetMarkers(); path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280); path.StartFigure(); path.SetMarkers(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.SetMarkers(); path.AddLine(new Point(400, 400), new Point(400, 10)); GraphicsPath path2 = new GraphicsPath(); path.AddLine(new Point(150, 150), new Point(450, 150)); path.AddLine(new Point(450, 250), new Point(50, 150)); GraphicsPathIterator iterator = new GraphicsPathIterator(path); iterator.NextMarker(null); iterator.NextMarker(path2); Assert.AreEqual(4, path2.PointCount); PointF [] actualPoints = path2.PathPoints; byte [] actualTypes = path2.PathTypes; PointF [] expectedPoints = new PointF [] { new PointF(100f, 100f), new PointF(400f, 100f), new PointF(400f, 200f), new PointF(10f, 100f) }; for (int i = 0; i < expectedPoints.Length; i++) { DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]); } byte [] expectedTypes = new byte [] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)(PathPointType.Line | PathPointType.PathMarker) }; for (int i = 0; i < expectedTypes.Length; i++) { Assert.AreEqual(expectedTypes [i], actualTypes [i]); } iterator.NextMarker(null); iterator.NextMarker(null); iterator.NextMarker(null); iterator.NextMarker(path2); Assert.AreEqual(4, path2.PointCount); actualPoints = path2.PathPoints; actualTypes = path2.PathTypes; expectedPoints = new PointF [] { new PointF(10f, 10f), new PointF(50f, 250f), new PointF(100f, 5f), new PointF(200f, 280f) }; for (int i = 0; i < expectedPoints.Length; i++) { DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]); } expectedTypes = new byte [] { (byte)PathPointType.Start, (byte)PathPointType.Bezier3, (byte)PathPointType.Bezier3, (byte)(PathPointType.Bezier3 | PathPointType.PathMarker) }; for (int i = 0; i < expectedTypes.Length; i++) { Assert.AreEqual(expectedTypes [i], actualTypes [i]); } }
/// <summary> /// The main entry point for the application. /// </summary> /// // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.CopyData(System.Drawing.PointF[]@,System.Byte[]@,System.Int32,System.Int32) // <snippet1> public void CopyDataExample(PaintEventArgs e) { // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up a points array. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; // Create a rectangle. Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add the points, rectangle, and an ellipse to the path. myPath.AddLines(myPoints); myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); // Get the total number of points for the path, and arrays of // the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing the array of points on the left // side of the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the set of points and types and types to the left side // of the screen. for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator for myPath and rewind it. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); myPathIterator.Rewind(); // Set up the arrays to receive the copied data. PointF[] points = new PointF[myPathIterator.Count]; byte[] types = new byte[myPathIterator.Count]; int myStartIndex; int myEndIndex; // Increment the starting index to the second marker in the // path. myPathIterator.NextMarker(out myStartIndex, out myEndIndex); myPathIterator.NextMarker(out myStartIndex, out myEndIndex); // Copy all the points and types from the starting index to the // ending index to the points array and the types array // respectively. int numPointsCopied = myPathIterator.CopyData( ref points, ref types, myStartIndex, myEndIndex); // List the copied points to the right side of the screen. j = 20; int copiedStartIndex = 0; for (i = 0; i < numPointsCopied; i++) { copiedStartIndex = myStartIndex + i; e.Graphics.DrawString( "Point: " + copiedStartIndex.ToString() + ", Value: " + points[i].ToString() + ", Type: " + types[i].ToString(), myFont, myBrush, 200, j); j += 20; } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { G = e.Graphics; G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; G.Clear(BackColor); Rectangle R = default(Rectangle); int Offset = 0; G.DrawRectangle(P1, 0, 0, (12 * 32) + 1, (5 * 32) + 1); for (int I = 0; I <= Buttons.Length - 1; I++) { R = Buttons[I]; Offset = 0; if (I == Pressed) { Offset = 1; GP1 = new GraphicsPath(); GP1.AddRectangle(R); PB1 = new PathGradientBrush(GP1); PB1.CenterColor = Color.FromArgb(60, 60, 60); PB1.SurroundColors = new Color[] { Color.FromArgb(55, 55, 55) }; PB1.FocusScales = new PointF(0.8f, 0.5f); G.FillPath(PB1, GP1); } else { GB1 = new LinearGradientBrush(R, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f); G.FillRectangle(GB1, R); } switch (I) { case 48: case 49: case 50: SZ1 = G.MeasureString(Other[I - 48], Font); G.DrawString(Other[I - 48], Font, Brushes.Black, R.X + (R.Width / 2 - SZ1.Width / 2) + Offset + 1, R.Y + (R.Height / 2 - SZ1.Height / 2) + Offset + 1); G.DrawString(Other[I - 48], Font, Brushes.White, R.X + (R.Width / 2 - SZ1.Width / 2) + Offset, R.Y + (R.Height / 2 - SZ1.Height / 2) + Offset); break; case 47: DrawArrow(Color.Black, R.X + Offset + 1, R.Y + Offset + 1); DrawArrow(Color.White, R.X + Offset, R.Y + Offset); break; default: if (Shift) { G.DrawString(Upper[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1, R.Y + 2 + Offset + 1); G.DrawString(Upper[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset); if (!char.IsLetter(Lower[I])) { PT1 = LowerCache[I]; G.DrawString(Lower[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset); } } else { G.DrawString(Lower[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1, R.Y + 2 + Offset + 1); G.DrawString(Lower[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset); if (!char.IsLetter(Upper[I])) { PT1 = UpperCache[I]; G.DrawString(Upper[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset); } } break; } G.DrawRectangle(P2, R.X + 1 + Offset, R.Y + 1 + Offset, R.Width - 2, R.Height - 2); G.DrawRectangle(P3, R.X + Offset, R.Y + Offset, R.Width, R.Height); if (I == Pressed) { G.DrawLine(P1, R.X, R.Y, R.Right, R.Y); G.DrawLine(P1, R.X, R.Y, R.X, R.Bottom); } } }
protected GraphicsPath GetPath() { GraphicsPath graphPath = new GraphicsPath(); if (_BorderStyle == BorderStyle.Fixed3D) { graphPath.AddRectangle(ClientRectangle); } else { try { int curve = 0; Rectangle rect = ClientRectangle; int offset = 0; switch (_BorderStyle) { case BorderStyle.FixedSingle: offset = (int) Math.Ceiling(BorderWidth / 2.0d); curve = adjustedCurve; break; case BorderStyle.Fixed3D: break; case BorderStyle.None: curve = adjustedCurve; break; } if (curve == 0) { graphPath.AddRectangle(Rectangle.Inflate(rect, -offset, -offset)); } else { int rectWidth = rect.Width - 1 - offset; int rectHeight = rect.Height - 1 - offset; int curveWidth; if ((_CurveMode & CornerCurveMode.TopRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90); if ((_CurveMode & CornerCurveMode.BottomRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90); if ((_CurveMode & CornerCurveMode.BottomLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90); if ((_CurveMode & CornerCurveMode.TopLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90); graphPath.CloseFigure(); } } catch (Exception) { graphPath.AddRectangle(ClientRectangle); } } return graphPath; }