public SetLineCap ( LineCap startCap, LineCap endCap, DashCap dashCap ) : void | ||
startCap | LineCap | |
endCap | LineCap | |
dashCap | DashCap | |
return | void |
public DrawCompass(Panel _panel) : base(_panel, _panel.Height / 2 - 20, _panel.Height / 10) { arrowPen = new Pen(Color.DarkGreen, 3.0f); LineCap lineCap = LineCap.ArrowAnchor; arrowPen.SetLineCap(lineCap, LineCap.Flat, DashCap.Flat); }
private void pnl_painter_MouseMove(object sender, MouseEventArgs e) { Brush brush1 = new SolidBrush(Color.Black); if (rdo_black.Checked) color = "black"; else if (rdo_blue.Checked) color = "blue"; else if (rdo_red.Checked) color = "red"; switch (color) { case "black": brush1 = new SolidBrush(Color.Black); break; case "blue": brush1 = new SolidBrush(Color.Blue); break; case "red": brush1 = new SolidBrush(Color.Red); break; } if (rdo_small.Checked) size = 4; else if (rdo_middle.Checked) size = 8; else if (rdo_large.Checked) size = 12; x2 = e.X; y2 = e.Y; Pen pen1 = new Pen(brush1, size); pen1.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Flat); //pen1.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; if (shouldPaint) { Graphics graphics = pnl_painter.CreateGraphics(); //graphics.FillEllipse(brush1, e.X, e.Y, size, size); graphics.DrawLine(pen1, x1, y1, x2, y2); graphics.Dispose(); } x1 = e.X; y1 = e.Y; }
public OpenObject(Form1 theForm) { callerForm = theForm; alphaPen = new Pen(Color.Purple, 10); alphaPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Flat); InitializeComponent(); }
public Pen GetPen() { Pen p = new Pen(this.Brush.GetBrush(), this.Width); p.SetLineCap(this.StartCap, this.EndCap, this.DashCap); p.DashStyle = this.DashStyle; p.LineJoin = this.LineJoin; return p; }
public override void Draw(Graphics graphics) { if (graphics == null) { throw new ArgumentNullException("graphics"); } using (Pen p = new Pen(this.ForeColor,this.Thickness)) { p.SetLineCap(this.StartLineCap,this.EndLineCap,this.DashLineCap); graphics.DrawLine(p,this.fromPoint,this.toPoint); } }
public override void Draw(Graphics graphics) { if (graphics == null) { throw new ArgumentNullException("graphics"); } using (var p = new Pen(ForeColor,Thickness)) { p.SetLineCap(StartLineCap,EndLineCap,DashLineCap); graphics.DrawLine(p,fromPoint,toPoint); } }
public Form1() { InitializeComponent(); koef.Text = k.ToString(); x0 = 0; y0 = 0; bmp = new Bitmap(pictureBox1.Width,pictureBox1.Height); bmp.MakeTransparent(Color.Black); pictureBox1.Image = bmp; MyPen = new System.Drawing.Pen(Color.Violet, 4); MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing. Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Round); time = System.DateTime.Now; }
protected override void OnRender(Graphics g, Point offset) { lock (this) { float ourSize = UI.ScaleWidth(Math.Min(Width, Height)); g.SmoothingMode = SmoothingMode.AntiAlias; g.TranslateTransform(-offset.X, -offset.Y, MatrixOrder.Append); PointF ptF = (PointF)this.Location; ptF = Utility.TransformOnePoint(this.transform, ptF); ptF.X *= (float)OwnerList.ScaleFactor.Ratio; ptF.Y *= (float)OwnerList.ScaleFactor.Ratio; PointF[] pts = new PointF[8] { new PointF(-1, -1), // up+left new PointF(+1, -1), // up+right new PointF(+1, +1), // down+right new PointF(-1, +1), // down+left new PointF(-1, 0), // left new PointF(+1, 0), // right new PointF(0, -1), // up new PointF(0, +1) // down }; Utility.RotateVectors(pts, this.transformAngle); Utility.NormalizeVectors(pts); using (Pen white = new Pen(Color.FromArgb(this.alpha, Color.White), -1.0f), black = new Pen(Color.FromArgb(this.alpha, Color.Black), -1.0f)) { PixelOffsetMode oldPOM = g.PixelOffsetMode; g.PixelOffsetMode = PixelOffsetMode.None; if (this.shape != MoveNubShape.Circle) { PointF[] outer = new PointF[4] { Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize)) }; PointF[] middle = new PointF[4] { Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize - 1)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize - 1)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize - 1)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize - 1)) }; PointF[] inner = new PointF[4] { Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize - 2)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize - 2)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize - 2)), Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize - 2)) }; g.DrawPolygon(white, outer); g.DrawPolygon(black, middle); g.DrawPolygon(white, inner); } else if (this.shape == MoveNubShape.Circle) { RectangleF rect = new RectangleF(ptF, new SizeF(0, 0)); rect.Inflate(ourSize - 1, ourSize - 1); g.DrawEllipse(white, rect); rect.Inflate(-1.0f, -1.0f); g.DrawEllipse(black, rect); rect.Inflate(-1.0f, -1.0f); g.DrawEllipse(white, rect); } if (this.shape == MoveNubShape.Compass) { black.SetLineCap(LineCap.Round, LineCap.DiamondAnchor, DashCap.Flat); black.EndCap = LineCap.ArrowAnchor; black.StartCap = LineCap.ArrowAnchor; white.SetLineCap(LineCap.Round, LineCap.DiamondAnchor, DashCap.Flat); white.EndCap = LineCap.ArrowAnchor; white.StartCap = LineCap.ArrowAnchor; PointF ul = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[0], ourSize - 1)); PointF ur = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[1], ourSize - 1)); PointF lr = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[2], ourSize - 1)); PointF ll = Utility.AddVectors(ptF, Utility.MultiplyVector(pts[3], ourSize - 1)); PointF top = Utility.MultiplyVector(Utility.AddVectors(ul, ur), 0.5f); PointF left = Utility.MultiplyVector(Utility.AddVectors(ul, ll), 0.5f); PointF right = Utility.MultiplyVector(Utility.AddVectors(ur, lr), 0.5f); PointF bottom = Utility.MultiplyVector(Utility.AddVectors(ll, lr), 0.5f); using (SolidBrush whiteBrush = new SolidBrush(white.Color)) { PointF[] poly = new PointF[] { ul, ur, lr, ll }; g.FillPolygon(whiteBrush, poly, FillMode.Winding); } g.DrawLine(black, top, bottom); g.DrawLine(black, left, right); } g.PixelOffsetMode = oldPOM; } } }
public void Begin() { m_pen = new Pen(System.Drawing.Color.Black, 2f); m_pen.SetLineCap(System.Drawing.Drawing2D.LineCap.Square, System.Drawing.Drawing2D.LineCap.Square, System.Drawing.Drawing2D.DashCap.Flat); }
// Create a solid pen public static Pen CreateSolidPen(Color color, float thickness, LineStyle style) { #if false Pen pen = new Pen(new SolidColorBrush(color), thickness); if (style == LineStyle.Rounded) { pen.StartLineCap = pen.EndLineCap = PenLineCap.Round; pen.LineJoin = PenLineJoin.Round; } else if (style == LineStyle.Beveled) { pen.StartLineCap = pen.EndLineCap = PenLineCap.Flat; pen.LineJoin = PenLineJoin.Bevel; } else if (style == LineStyle.Mitered) { pen.StartLineCap = pen.EndLineCap = PenLineCap.Flat; pen.LineJoin = PenLineJoin.Miter; pen.MiterLimit = MITER_LIMIT; } else if (style == LineStyle.FlatRounded) { pen.StartLineCap = pen.EndLineCap = PenLineCap.Flat; pen.LineJoin = PenLineJoin.Round; } pen.Freeze(); return pen; #else Pen pen = new Pen(color, thickness); if (style == LineStyle.Rounded) { pen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Flat); pen.LineJoin = LineJoin.Round; } else if (style == LineStyle.Beveled) { pen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat); pen.LineJoin = LineJoin.Bevel; } else if (style == LineStyle.Mitered) { pen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat); pen.LineJoin = LineJoin.Miter; pen.MiterLimit = MITER_LIMIT; } else if (style == LineStyle.FlatRounded) { pen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat); pen.LineJoin = LineJoin.Round; } return pen; #endif }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingQuality = CompositingQuality.HighQuality; Pen p = new Pen(Brush, 4); p.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat); var gp = new GraphicsPath(); gp.AddLine(4, 10, 4, 40); gp.AddArc(4, 5, 10, 10, 180, 90); gp.AddLine(9, 5, 12, 5); gp.AddArc(12, 5, 10, 10, 270, 90); gp.AddLine(22, 10, 22, 30); gp.AddArc(12, 34, 10, 10, 0, 90); gp.AddLine(16, 44, 12, 44); gp.AddArc(4, 34, 10, 10, 90, 90); g.DrawPath(p, gp); bool on = Value > 0.5; if (Invert) on = !on; if (Mode == SwitchMode.Toggle) on = on && MouseIsDown; if(on) g.FillRectangle(Brush, 9, 10, 8, 10); else g.FillRectangle(OffBrush, 9, 29, 8, 10); }
private void PictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { int directionX; int directionY; switch (this.Direction) { case Direction.UpLeft: directionX = -1; directionY = -1; break; case Direction.Left: directionX = -1; directionY = 0; break; case Direction.DownLeft: directionX = -1; directionY = 1; break; case Direction.Down: directionX = 0; directionY = 1; break; case Direction.Right: directionX = 1; directionY = 0; break; case Direction.UpRight: directionX = 1; directionY = -1; break; case Direction.Up: directionX = 0; directionY = -1; break; default: //Direction.DownRight directionX = 1; directionY = 1; break; } System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, 3); pen.SetLineCap(System.Drawing.Drawing2D.LineCap.Flat, System.Drawing.Drawing2D.LineCap.ArrowAnchor, System.Drawing.Drawing2D.DashCap.Flat); int center = Convert.ToInt32(PictureBox1.Width / 2); int radius = center - 1; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; e.Graphics.DrawLine(pen, center, center, center + radius * directionX, center + radius * directionY); }
private void PaintLine(Graphics g, SnapshotIcon icon, SnapshotIcon child, bool highlight) { if (child.Index == -1) return; try { Rectangle leftItemBounds = icon.GetBounds(ItemBoundsPortion.Entire); Rectangle rightItemBounds = child.GetBounds(ItemBoundsPortion.Entire); leftItemBounds.Size = icon.DefaultSize; rightItemBounds.Size = child.DefaultSize; int left = leftItemBounds.Right + 6; int right = rightItemBounds.Left; int mid = (left + right) / 2; Point start = new Point(left, (leftItemBounds.Bottom + leftItemBounds.Top) / 2); Point end = new Point(right, (rightItemBounds.Top + rightItemBounds.Bottom) / 2); Point curveStart = start; curveStart.Offset(straightLineLength, 0); Point curveEnd = end; curveEnd.Offset(-straightLineLength, 0); Point control1 = new Point(mid + straightLineLength, start.Y); Point control2 = new Point(mid - straightLineLength, end.Y); Color lineColor = LinkLineColor; float lineWidth = LinkLineWidth; if (highlight) { lineColor = Color.ForestGreen; lineWidth = 2.5f; } using (Pen p = new Pen(lineColor, lineWidth)) { p.SetLineCap(LineCap.Round, LineCap.Custom, DashCap.Flat); p.CustomEndCap = linkLineArrow; g.SmoothingMode = SmoothingMode.AntiAlias; GraphicsPath path = new GraphicsPath(); path.AddLine(start, curveStart); path.AddBezier(curveStart, control1, control2, curveEnd); path.AddLine(curveEnd, end); g.DrawPath(p, path); } } catch (Exception) { //Debugger.Break(); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; Rectangle rcClient = ClientRectangle; rcClient.Inflate(-4, -4); Region originalClip = g.Clip; g.Clip = new Region(rcClient); g.SmoothingMode = SmoothingMode.AntiAlias; Size szSpace = new Size(4, 3); Rectangle rcItem; Rectangle rcText = new Rectangle(0, 0, 0, 0); Rectangle rcIcon = new Rectangle(0, 0, 0, 0); StringFormat iconTextFormat = new StringFormat(); iconTextFormat.Alignment = StringAlignment.Center; iconTextFormat.LineAlignment = StringAlignment.Center; Color color1 = Color.White; Color color2 = Color.White; Brush textBrush = Brushes.Black; Brush iconBrush = Brushes.White; //First determine if the data will fit without the scrollbar rcItem = new Rectangle(rcClient.X, rcClient.Y + mCurrentY, rcClient.Width - szSpace.Width, 0); for (int i = 0; i < Items.Count; i++) { ListItem item = Items[i]; if (item.Icon != null) { rcIcon = new Rectangle(ItemPadding.Left + rcItem.X, 0, item.Icon.Width, item.Icon.Height); rcText.X = rcIcon.Right + szSpace.Width; rcText.Width = rcItem.Width - (szSpace.Width + rcIcon.Width + ItemPadding.Left + ItemPadding.Right); } else { rcIcon = new Rectangle(0, 0, 0, 0); rcText.X = ItemPadding.Left + rcItem.X; rcText.Width = rcItem.Width - (ItemPadding.Left + ItemPadding.Right); } Size sz = g.MeasureString(item.Text, Font, rcText.Width).ToSize(); rcItem.Height = ((item.Icon != null && sz.Height < rcIcon.Height) ? rcIcon.Height : sz.Height) + (szSpace.Height * 2) + ItemPadding.Top + ItemPadding.Bottom; item.Size = rcItem.Size; item.Location.X = rcItem.Location.X; item.Location.Y = rcItem.Location.Y + mCurrentY; rcText.Height = rcItem.Height; rcText.Y = rcItem.Y; rcIcon.Y = rcItem.Y + ((rcItem.Height - rcIcon.Height) / 2); rcItem.Offset(0, rcItem.Height + szSpace.Height); } mMaxScroll = ((rcItem.Bottom + mDefaultY) - (Height + mCurrentY)); if (mMaxScroll < 0) { // No scrolling needed mMaxScroll = 0; mCurrentY = mDefaultY; mScrollBar = new Rectangle(0, 0, 0, 0); } else { mScrollBar = new Rectangle(rcClient.Right - 30, rcClient.Y, 30, rcClient.Height); RoundRectPath thumbPath = new RoundRectPath(mScrollBar, mRounding, mRounding); using (LinearGradientBrush b = new LinearGradientBrush(mScrollBar, Color.White, Color.LightGray, LinearGradientMode.Vertical)) { b.WrapMode = WrapMode.TileFlipX; g.FillPath(b, thumbPath); } using (Pen p = new Pen(Color.DarkGray, 3)) { p.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round); g.DrawLine(p, new Point(mScrollBar.X + 6, 18), new Point(mScrollBar.X + 15, 8)); g.DrawLine(p, new Point(mScrollBar.X + 24, 18), new Point(mScrollBar.X + 15, 8)); g.DrawLine(p, new Point(mScrollBar.X + 6, mScrollBar.Bottom - 18), new Point(mScrollBar.X + 15, mScrollBar.Bottom - 8)); g.DrawLine(p, new Point(mScrollBar.X + 24, mScrollBar.Bottom - 18), new Point(mScrollBar.X + 15, mScrollBar.Bottom - 8)); } for (int l = 24; l < rcClient.Height - 24; l += 4) { g.DrawLine(Pens.DarkGray, new Point(mScrollBar.Location.X + 6, l), new Point(mScrollBar.Location.X + 24, l)); } g.DrawPath(Pens.Black, thumbPath); thumbPath.Dispose(); } rcItem = new Rectangle(rcClient.X, rcClient.Y + mCurrentY, rcClient.Width - ((mScrollBar.Width > 0) ? mScrollBar.Width + szSpace.Width : 0), 0); for (int i = 0; i < Items.Count; i++) { ListItem item = Items[i]; if (item.Icon != null) { rcIcon = new Rectangle(ItemPadding.Left + rcItem.X, 0, item.Icon.Width, item.Icon.Height); rcText.X = rcIcon.Right + szSpace.Width; rcText.Width = rcItem.Width - (szSpace.Width + rcIcon.Width + ItemPadding.Left + ItemPadding.Right); } else { rcIcon = new Rectangle(0, 0, 0, 0); rcText.X = ItemPadding.Left + rcItem.X; rcText.Width = rcItem.Width - (ItemPadding.Left + ItemPadding.Right); } Size sz = g.MeasureString(item.Text, Font, rcText.Width).ToSize(); rcItem.Height = ((item.Icon != null && sz.Height < rcIcon.Height) ? rcIcon.Height : sz.Height) + (szSpace.Height * 2) + ItemPadding.Top + ItemPadding.Bottom; item.Size = rcItem.Size; item.Location.X = rcItem.Location.X; item.Location.Y = rcItem.Location.Y + mCurrentY; rcText.Height = rcItem.Height; rcText.Y = rcItem.Y; rcIcon.Y = rcItem.Y + ((rcItem.Height - rcIcon.Height) / 2); DrawItem(new ListItemPaintArgs(g, item, rcItem, rcText, rcIcon)); rcItem.Offset(0, rcItem.Height + szSpace.Height); } iconTextFormat.Dispose(); g.Clip.Dispose(); g.Clip = originalClip; }
public void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; using (Pen axisPen = new Pen(AxisColor, AxisWidth)) using (Pen majorPen = new Pen(AxisColor, MajorTickWidth)) using (Pen minorPen = new Pen(AxisColor, MinorTickWidth)) using (Brush labelBrush = new SolidBrush(LabelColor)) { axisPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round); majorPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round); minorPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round); try { g.DrawPath(axisPen, m_arcPath); g.DrawPath(majorPen, m_majorTicksPath); g.DrawPath(minorPen, m_minorTicksPath); g.FillPath(labelBrush, m_labelPath); } catch { } } //now these areas need to be redrawn if they change m_redrawRegion.Dispose(); m_redrawRegion = new Region(); m_redrawRegion.Union(m_arcPath); m_redrawRegion.Union(m_labelPath); m_redrawRegion.Union(m_majorTicksPath); m_redrawRegion.Union(m_minorTicksPath); }
public void SetLineCap_InvalidEndCap () { using (Pen p = new Pen (Brushes.Red)) { p.SetLineCap (LineCap.Flat, (LineCap)Int32.MinValue, DashCap.Flat); // no exception :( (reported as FDBK50057) Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap"); Assert.AreEqual (Int32.MinValue, (int)p.EndCap, "EndCap"); Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap"); } }
private void displayGraph(PointList points) { SolidBrush blackBrush = new SolidBrush(Color.Black); SolidBrush redBrush = new SolidBrush(Color.Red); Pen pen = new Pen(blackBrush, 1); Pen arrowPen = new Pen(new SolidBrush(Color.Gray), 6); arrowPen.DashStyle = DashStyle.Solid; arrowPen.SetLineCap(LineCap.NoAnchor, LineCap.ArrowAnchor, DashCap.Flat); Graphics graphics = picGraph.CreateGraphics(); graphics.Clear(Color.White); foreach (Point p in points) drawPoint(graphics, blackBrush, p); for (int i = 0; i < points.Count - 1; i++) drawArc(graphics, pen, arrowPen, points[i], points[i + 1]); if (points.Count > 0) drawPoint(graphics, redBrush, points[0]); pen.Dispose(); blackBrush.Dispose(); redBrush.Dispose(); graphics.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingQuality = CompositingQuality.HighQuality; Pen p = new Pen(Brush, 5); p.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat); g.DrawArc(p, 4, 4, 42, 42, 45, -270); float vectorX = (float)Math.Cos(Rad(218) - Value * Rad(256)); float vectorY = (float)-Math.Sin(Rad(218) - Value * Rad(256)); g.DrawLine(p, 25 + 5*vectorX, 25 + 5*vectorY, 25f + 23f*vectorX, 25 + 23f*vectorY); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; #region 区域声明以及提前判断 topInfoRect = new Rectangle(0, 1, this.Width, 25); if (_isInit) { ellipseBarRect = new Rectangle(this.Width - 11, topInfoRect.Height + 3, 10, 20); _isInit = false; } else { ellipseBarRect = new Rectangle(this.Width - 11, ellipseBarRect.Y, ellipseBarRect.Width, ellipseBarRect.Height); } gBarRect = new Rectangle(this.Width - 11, topInfoRect.Height + 3, 10, this.Height - topInfoRect.Height - 4); g.Clear(Color.FromArgb(244, 249, 239)); if (Items.Count > 0) { int height = (gBarRect.Height / _itemHeight) * gBarRect.Height / Items.Count; int y = ellipseBarRect.Y - (ellipseBarRect.Height - height); if (ellipseBarRect.Y < y) y = ellipseBarRect.Y; if (y < topInfoRect.Height + 3) y = topInfoRect.Height + 3; ellipseBarRect = new Rectangle( ellipseBarRect.X, y, ellipseBarRect.Width, height); } if (ellipseBarRect.Height < barMinSize) { ellipseBarRect = new Rectangle( ellipseBarRect.X, ellipseBarRect.Y, ellipseBarRect.Width, barMinSize); } #endregion if (Items.Count > 0) { //offsetY = // (ellipseBarRect.Y - topInfoRect.Height - 3) * // (Items.Count * _itemHeight) / gBarRect.Height; int gh = (gBarRect.Height / _itemHeight) * gBarRect.Height / Items.Count; int elY = (ellipseBarRect.Y - topInfoRect.Height - 3); offsetY = (int)(elY * ((double)(Items.Count * _itemHeight) / gBarRect.Height)); #region 绘制列表项 Font itemFont = new Font("微软雅黑", 9); int maxLength = 100; int subStart = 0; int subEnd = 0; if (offsetY > 0) subStart = (offsetY / _itemHeight) - 1; if (subStart < 0) subStart = 0; subEnd = ((this.ClientRectangle.Height - topInfoRect.Height - 3 + offsetY) / _itemHeight) + 1; if (subEnd > Items.Count) subEnd = Items.Count; for (int i = subStart; i < subEnd; i++) { if ((i * _itemHeight) - offsetY + topInfoRect.Height > topInfoRect.Height - _itemHeight) { Rectangle itemRect = new Rectangle(1, (i * _itemHeight) - offsetY + topInfoRect.Height, this.Width - 2 - ellipseBarRect.Width, _itemHeight); Rectangle musicName = new Rectangle(itemRect.X, itemRect.Y, itemRect.Width - maxLength, _itemHeight); Rectangle sharePerson = new Rectangle(itemRect.X + (itemRect.Width - maxLength), itemRect.Y, maxLength, _itemHeight); Items[i].Rect = itemRect; if (_downEntity == Items[i]) { g.FillRectangle(new SolidBrush(Color.FromArgb(205, 227, 180)), itemRect); } if (_hoverEntity == Items[i] && _hoverEntity != _downEntity) { g.FillRectangle(new SolidBrush(Color.FromArgb(222, 237, 206)), itemRect); } TextRenderer.DrawText( g, Items[i].MusicName, itemFont, musicName, Color.FromArgb(85, 85, 85), Color.Transparent, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); TextRenderer.DrawText( g, Items[i].SharePeople, new Font("微软雅黑", 9), sharePerson, Color.FromArgb(85, 85, 85), Color.Transparent, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); } } #endregion #region 绘制滚动条 Pen pens = new Pen(Color.FromArgb(170, 174, 167), ellipseBarRect.Width); pens.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round); if (_isEllipeBarHover) { pens.Color = Color.FromArgb(122, 124, 119); } else if (_isEllipeBarDown) { pens.Color = Color.FromArgb(73, 74, 71); } g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.DrawLine(pens, ellipseBarRect.X + 5, ellipseBarRect.Y + 5, ellipseBarRect.X + 5, ellipseBarRect.Y + ellipseBarRect.Height - 5); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; //g.DrawRectangle(Pens.Red, ellipseBarRect); //g.DrawRectangle(Pens.Red, gBarRect); #endregion #region 绘制虚线以及多少首歌 g.FillRectangle(new SolidBrush(Color.FromArgb(244, 249, 239)), topInfoRect); using (Pen dashedPen = new Pen(Color.FromArgb(196, 207, 182))) { dashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; g.DrawLine(dashedPen, 0, 26, this.Width, 26); } TextRenderer.DrawText( g, string.Format("共{0}首歌曲", Items.Count), new Font("微软雅黑", 9), topInfoRect, Color.FromArgb(185, 185, 185), Color.Transparent, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); #endregion #region 在显示歌曲总数区域绘制选择页数 //g.DrawRectangle(Pens.Red, topInfoRect); for (int i = 0; i < _buttons.Count; i++) { SmallButton item = _buttons[i]; if (_hoverButton != item) { item.DownState = DownState.Normal; } item.ButtonRect = new Rectangle( i * 20 + (topInfoRect.Width - (20 * _buttons.Count)), topInfoRect.Top + (topInfoRect.Height / 2) - 10, 18, 18); item.Draw(g); } #endregion } #region 动画效果 else { Size size = TextRenderer.MeasureText("列表正在加载", this.Font); if (play == null) { play = new GifPlay(Resources.ScanLoader); play.Play(); play.OnFrameChanged += play_OnFrameChanged; addPointStr = new System.Threading.Timer(new TimerCallback(delegate(object obj) { if (pointStrs.Length >= 6) pointStrs.Remove(0, 6); else pointStrs.Append("."); if (Items.Count > 0) { if (play != null) { play.Stop(); play = null; } addPointStr.Dispose(); } }), null, 0, 200); g.DrawImage(play.Image, new Rectangle(this.Width / 2 - size.Width / 2 - 16, this.Height / 2 - 8, 16, 16)); base.Invalidate(); } else { lock (play.Image) { TextRenderer.DrawText( g, "列表正在加载" + pointStrs.ToString(), this.Font, new Rectangle(this.Width / 2 - size.Width / 2, 0, this.Width, this.Height), Color.Black, Color.Transparent, TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter); g.DrawImage(play.Image, new Rectangle(this.Width / 2 - size.Width / 2 - 16, this.Height / 2 - size.Height / 2 - 1, 16, 16)); } } } #endregion }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; Graphics g = e.Graphics; //Deflat rect for body Rectangle rcClient = ClientRectangle; rcClient.Width -= 3; rcClient.Height -= 3; rcClient.Offset(1, 1); if (g.Clip != null) g.Clip.Dispose(); g.Clip = new Region(rcClient); g.SmoothingMode = SmoothingMode.AntiAlias; if (mHeaderFont == null) { mHeaderFont = new Font(Font, FontStyle.Bold); } Rectangle rcHeader = new Rectangle(rcClient.X, rcClient.Y, rcClient.Width, mHeaderFont.Height + 10); Rectangle rcText = new Rectangle(0, 0, 1, rcHeader.Height); //Draw header background RoundRectPath path = new RoundRectPath(rcHeader, mRounding, mRounding); Color grad = Color.FromArgb((Color.LightGray.R + 150) <= 255 ? Color.LightGray.R + 100 : 255, (Color.LightGray.G + 150) <= 255 ? Color.LightGray.G + 150 : 255, (Color.LightGray.B + 150) <= 255 ? Color.LightGray.B + 150 : 255); using (LinearGradientBrush b = new LinearGradientBrush(new Rectangle(rcHeader.X, rcHeader.Y - (rcHeader.Height / 2), rcHeader.Width, rcHeader.Height + (rcHeader.Height / 2)), grad, Color.LightGray, LinearGradientMode.Vertical)) { b.WrapMode = WrapMode.TileFlipX; g.FillPath(b, path); } using (Pen p = new Pen(Color.DarkGray, 1)) { //g.DrawLine(p, new Point(rcHeader.Left, rcHeader.Bottom), new Point(rcHeader.Right, rcHeader.Bottom)); g.DrawPath(p, path); } path.Dispose(); //Draw header text rcText = rcHeader; foreach (GridColumn col in mColumns) { rcText.Width = col.Width; format.Alignment = col.Alignment; g.DrawString(col.HeaderText, mHeaderFont, Brushes.Black, rcText, format); rcText.Offset(col.Width, 0); } rcClient.Inflate(-1, -1); if (g.Clip != null) g.Clip.Dispose(); g.Clip = new Region(rcClient); rcClient.Y = rcHeader.Bottom; rcClient.Height = ClientRectangle.Height - (rcHeader.Height + 1); if (g.Clip != null) g.Clip.Dispose(); g.Clip = new Region(rcClient); int height = ((rcHeader.Height - 8) * (mRows.Count)) + 4; rcText.Height = mHeaderFont.Height + 2; mMaxScroll = rcClient.Height - height; if (mMaxScroll > 0) { // No scrolling needed mMaxScroll = 0; mScrollBar = new Rectangle(0, 0, 0, 0); } else { mScrollBar = new Rectangle(rcClient.Right - 33, rcClient.Y + 3, 30, rcClient.Height - 6); RoundRectPath thumbPath = new RoundRectPath(mScrollBar, mRounding, mRounding); using (LinearGradientBrush b = new LinearGradientBrush(mScrollBar, Color.White, Color.LightGray, LinearGradientMode.Vertical)) { b.WrapMode = WrapMode.TileFlipX; g.FillPath(b, thumbPath); } using (Pen p = new Pen(Color.DarkGray, 3)) { p.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round); g.DrawLine(p, new Point(mScrollBar.X + 6, mScrollBar.Y + 18), new Point(mScrollBar.X + 15, mScrollBar.Y + 8)); g.DrawLine(p, new Point(mScrollBar.X + 24, mScrollBar.Y + 18), new Point(mScrollBar.X + 15, mScrollBar.Y + 8)); g.DrawLine(p, new Point(mScrollBar.X + 6, mScrollBar.Bottom - 18), new Point(mScrollBar.X + 15, mScrollBar.Bottom - 8)); g.DrawLine(p, new Point(mScrollBar.X + 24, mScrollBar.Bottom - 18), new Point(mScrollBar.X + 15, mScrollBar.Bottom - 8)); } for (int l = mScrollBar.Y + 24; l < mScrollBar.Bottom - 24; l += 4) { g.DrawLine(Pens.DarkGray, new Point(mScrollBar.Location.X + 6, l), new Point(mScrollBar.Location.X + 24, l)); } g.DrawPath(Pens.Black, thumbPath); rcClient.Width = rcClient.Width - (mScrollBar.Width + 6); if (g.Clip != null) g.Clip.Dispose(); g.Clip = new Region(rcClient); thumbPath.Dispose(); if (g.Clip != null) g.Clip.Dispose(); } Brush bActive = new SolidBrush(Color.FromArgb(0xBC, 0xC9, 0xFE)); Brush bError = new SolidBrush(Color.Pink); Brush bSuccess = new SolidBrush(Color.LightGreen); Brush bCustom = new SolidBrush(mCustomBackColor); //Fill Row back colors Rectangle rcRow = new Rectangle(rcClient.X, rcClient.Y + mCurrentY, rcClient.Width, mHeaderFont.Height + 2); for (int row = 0; row < mRows.Count; row++) { if (rcRow.Bottom > rcClient.Bottom) break; if (mSelectMode) { if (row == mSelecedIndex) g.FillRectangle(bActive, rcRow); } else if (mRows[row].Style == GridRowStyle.Active) { g.FillRectangle(bActive, rcRow); } else if (mRows[row].Style == GridRowStyle.Success) { g.FillRectangle(bSuccess, rcRow); } else if (mRows[row].Style == GridRowStyle.Error) { g.FillRectangle(bError, rcRow); } else if (mRows[row].Style == GridRowStyle.Custom) { g.FillRectangle(bCustom, rcRow); } rcRow.Offset(0, rcRow.Height); } Brush textBrush = null; Brush customForeBrush = new SolidBrush(mCustomForeColor); rcRow = new Rectangle(rcClient.X, rcClient.Y + mCurrentY, rcClient.Width, mHeaderFont.Height + 2); foreach (GridRow row in mRows) { if (rcRow.Bottom > rcClient.Bottom) break; rcText.X = rcRow.X; rcText.Y = rcRow.Y; for(int i = 0; i < mColumns.Count; i++) { if (i < row.Values.Count) { rcText.Width = mColumns[i].Width; format.Alignment = mColumns[i].Alignment; switch (row.Style) { case GridRowStyle.Inactive: textBrush = Brushes.Gray; break; case GridRowStyle.Custom: textBrush = customForeBrush; break; default: textBrush = Brushes.Black; break; } format.FormatFlags = StringFormatFlags.NoWrap; g.DrawString(row.Values[i], Font, textBrush, rcText, format); rcText.Offset(mColumns[i].Width, 0); } } rcRow.Offset(0, rcRow.Height); } bActive.Dispose(); bError.Dispose(); bSuccess.Dispose(); bCustom.Dispose(); customForeBrush.Dispose(); format.Dispose(); }
/// <summary> /// Draw one subdivision curve. /// </summary> /// <param name="output">Target bitmap.</param> /// <param name="P">Array of control points.</param> /// <param name="col">Drawing color.</param> public static void DrawCurve(Bitmap output, List<Vector2d> P, Color col, int levelsCount = 0) { // !!!{{ TODO: write your own subdivision curve rasterization code here if (P.Count < 1) return; if (levelsCount > 0 && P.Count >= 2) { if (avgMask == mask.CHAIKIN) DrawCurve(output, RefineChaikin(P), col, levelsCount - 1); else if (avgMask == mask.B3SPLINE) DrawCurve(output, RefineBSpline3(P), col, levelsCount - 1); else if (avgMask == mask.DLG) DrawCurve(output, RefineDLG(P), col, levelsCount - 1); return; } Graphics gfx = Graphics.FromImage(output); gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Pen pen = new Pen(col, lineWidth); pen.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Round); if (P.Count == 1) { gfx.DrawEllipse(pen, (float)P[0].X - 1f, (float)P[0].Y - 1f, 2f, 2f); } else { for (int i = 0; i < P.Count - 1; i++) //Draw.Line( output, (int)Math.Round( P[ i ].X ), (int)Math.Round( P[ i ].Y ), (int)Math.Round( P[ i + 1 ].X ), (int)Math.Round( P[ i + 1 ].Y ), col ); gfx.DrawLine(pen, (float)P[i].X, (float)P[i].Y, (float)P[i + 1].X, (float)P[i + 1].Y); gfx.Dispose(); } // !!!}} }
private static Pen GetStroke( ContentScanner.GraphicsState state ) { Pen stroke = new Pen( state.StrokeColorSpace.GetPaint(state.StrokeColor), (float)state.LineWidth ); { LineCap lineCap = state.LineCap.ToGdi(); stroke.SetLineCap(lineCap, lineCap, lineCap.ToDashCap()); stroke.LineJoin = state.LineJoin.ToGdi(); stroke.MiterLimit = (float)state.MiterLimit; LineDash lineDash = state.LineDash; double[] dashArray = lineDash.DashArray; if(dashArray != null && dashArray.Length > 0) { stroke.DashPattern = ConvertUtils.ToFloatArray(dashArray); stroke.DashOffset = (float)lineDash.DashPhase; } } return stroke; }
private void DrawToGraphics(Graphics g) { PointF clientPos = new PointF( (this.position.X * this.dragAreaRect.Width) / ClientSize.Width, (this.position.Y * this.dragAreaRect.Height) / ClientSize.Height); PointF ptCenter = new PointF(ClientSize.Width / 2.0f, ClientSize.Height / 2.0f); PointF ptDot = new PointF((1 + clientPos.X) * ClientSize.Width / 2.0f, (1 + clientPos.Y) * ClientSize.Height / 2.0f); PointF ptArrow; if (-1 <= clientPos.X && clientPos.X <= 1 && -1 <= clientPos.Y && clientPos.Y <= 1) { ptArrow = new PointF((1 + clientPos.X) * ClientSize.Width / 2, (1 + clientPos.Y) * ClientSize.Height / 2); } else { ptArrow = new PointF((1 + clientPos.X) * ClientSize.Width / 2, (1 + clientPos.Y) * ClientSize.Height / 2); if (Math.Abs(clientPos.X) > Math.Abs(clientPos.Y)) { if (clientPos.X > 0) { ptArrow.X = ClientSize.Width - 1; ptArrow.Y = (1 + clientPos.Y / clientPos.X) * ClientSize.Height / 2; } else { ptArrow.X = 0; ptArrow.Y = (1 - clientPos.Y / clientPos.X) * ClientSize.Height / 2; } } else { if (clientPos.Y > 0) { ptArrow.X = (1 + clientPos.X / clientPos.Y) * ClientSize.Width / 2; ptArrow.Y = ClientSize.Height - 1; } else { ptArrow.X = (1 - clientPos.X / clientPos.Y) * ClientSize.Width / 2; ptArrow.Y = 0; } } } CompositingMode oldCM = g.CompositingMode; g.CompositingMode = CompositingMode.SourceCopy; g.Clear(this.BackColor); g.CompositingMode = CompositingMode.SourceOver; if (this.staticImageUnderlay != null) { Size dstSize; if (this.cachedUnderlay != null) { dstSize = new Size(this.cachedUnderlay.Width, this.cachedUnderlay.Height); } else { Image image = this.staticImageUnderlay.Reference; Rectangle srcRect = new Rectangle(0, 0, image.Width, image.Height); Size maxThumbSize = new Size( Math.Max(1, Math.Min(ClientSize.Width - 4, srcRect.Width)), Math.Max(1, Math.Min(ClientSize.Height - 4, srcRect.Height))); dstSize = Utility.ComputeThumbnailSize(image.Size, Math.Min(maxThumbSize.Width, maxThumbSize.Height)); this.cachedUnderlay = new Bitmap(dstSize.Width, dstSize.Height, PixelFormat.Format24bppRgb); Surface checkers = new Surface(dstSize); checkers.ClearWithCheckboardPattern(); Bitmap checkersBmp = checkers.CreateAliasedBitmap(); Rectangle gcuRect = new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height); using (Graphics gcu = Graphics.FromImage(this.cachedUnderlay)) { gcu.CompositingMode = CompositingMode.SourceOver; gcu.DrawImage(checkersBmp, gcuRect, new Rectangle(0, 0, checkersBmp.Width, checkersBmp.Height), GraphicsUnit.Pixel); gcu.InterpolationMode = InterpolationMode.HighQualityBicubic; RectangleF gcuRect2 = RectangleF.Inflate(gcuRect, 0.5f, 0.5f); gcu.DrawImage(image, gcuRect2, srcRect, GraphicsUnit.Pixel); } checkersBmp.Dispose(); checkersBmp = null; checkers.Dispose(); checkers = null; } Rectangle dstRect = new Rectangle((ClientSize.Width - dstSize.Width) / 2, (ClientSize.Height - dstSize.Height) / 2, dstSize.Width, dstSize.Height); g.DrawImage(this.cachedUnderlay, dstRect, new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height), GraphicsUnit.Pixel); g.DrawRectangle(Pens.Black, new Rectangle(dstRect.Left - 1, dstRect.Top - 1, dstRect.Width + 1, dstRect.Height + 1)); Utility.DrawDropShadow1px(g, new Rectangle(dstRect.Left - 2, dstRect.Top - 2, dstRect.Width + 4, dstRect.Height + 4)); } PixelOffsetMode oldPOM = g.PixelOffsetMode; g.PixelOffsetMode = PixelOffsetMode.Half; SmoothingMode oldSM = g.SmoothingMode; g.SmoothingMode = SmoothingMode.HighQuality; // Draw the center -> end point arrow using (Pen pen = (Pen)Pens.Black.Clone()) { pen.SetLineCap(LineCap.Round, LineCap.DiamondAnchor, DashCap.Flat); pen.EndCap = LineCap.ArrowAnchor; pen.Width = 2.0f; pen.Color = SystemColors.ControlDark; g.DrawLine(pen, ptCenter, ptArrow); } // Draw the compass using (Pen pen = new Pen(Color.White)) { pen.SetLineCap(LineCap.DiamondAnchor, LineCap.DiamondAnchor, DashCap.Flat); // Draw white outline pen.Width = 3f; pen.Color = Color.White; g.DrawLine(pen, ptDot.X - 5.0f, ptDot.Y, ptDot.X + 5.0f, ptDot.Y); g.DrawLine(pen, ptDot.X, ptDot.Y - 5.0f, ptDot.X, ptDot.Y + 5.0f); // Draw black inset pen.Width = 2f; pen.Color = Color.Black; g.DrawLine(pen, ptDot.X - 5.0f, ptDot.Y, ptDot.X + 5.0f, ptDot.Y); g.DrawLine(pen, ptDot.X, ptDot.Y - 5.0f, ptDot.X, ptDot.Y + 5.0f); } g.SmoothingMode = oldSM; g.PixelOffsetMode = oldPOM; g.CompositingMode = oldCM; }
public void SetLineCap () { using (Pen p = new Pen (Brushes.Red)) { foreach (LineCap sc in Enum.GetValues (typeof (LineCap))) { foreach (LineCap ec in Enum.GetValues (typeof (LineCap))) { foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) { string s = String.Format ("{0}-{1}-{2}", sc, ec, dc); p.SetLineCap (sc, ec, dc); Assert.AreEqual (sc, p.StartCap, s + ".StartCap"); Assert.AreEqual (ec, p.EndCap, s + ".EndCap"); Assert.AreEqual (dc, p.DashCap, s + ".DashCap"); } } } } }
private Bitmap drawEdges(List<Edge> edges, bool drawCenter) { int minrad = (int)Math.Ceiling(Program.PitchPitch.Player.MaxRadius * 0.5 / (double)_chipHeight); int maxrad = (int)Math.Ceiling(Program.PitchPitch.Player.MaxRadius * 1.6 / (double)_chipHeight); if(minrad == 0) minrad = 1; double coef = _vx; Brush onBr = new SolidBrush(HoleColor); Brush offBr = new SolidBrush(HoleColor); Brush dipBr = new SolidBrush(HoleColor); Pen centerPen = new Pen(CenterColor, 1); centerPen.SetLineCap(LineCap.Flat, LineCap.Flat, DashCap.Flat); Bitmap bmp = new Bitmap(_width, _height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(bmp)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; g.Clear(WallColor); #region hole foreach (Edge e in edges) { Point sp = e.StartPoint.Point; Point ep = e.EndPoint.Point; switch (e.Type) { case EdgeType.On: #region On drawPoint(g, onBr, sp, minrad, maxrad); drawPoint(g, onBr, ep, minrad, maxrad); g.FillRectangle(onBr, sp.X, sp.Y - minrad, ep.X - sp.X, ep.Y - sp.Y + minrad * 2 + 2); #endregion break; case EdgeType.Off: #region Off drawPoint(g, offBr, sp, minrad, maxrad); drawPoint(g, offBr, ep, minrad, maxrad); g.FillRectangle(offBr, sp.X, sp.Y - maxrad, ep.X - sp.X, ep.Y - sp.Y + maxrad * 2 + 2); #endregion break; case EdgeType.Dip: #region Dip double w = Math.Abs(sp.Y - ep.Y) * coef; int xend = (int)(sp.X + w); bool toolong = false; int sx = 0; Edge endEdge = e.EndPoint.Edges.Find((fe) => { return fe.StartPoint == e.EndPoint; }); if (endEdge != null) { sx = endEdge.EndPoint.Point.X; if (sx < xend) { toolong = true; int tmp = (int)(sp.X + w * 0.4); if(sx < tmp) sx = tmp; } } List<Point> points = new List<Point>(); points.Add(new Point(sp.X + minrad, sp.Y)); points.Add(new Point(sp.X - minrad, sp.Y)); points.Add(new Point(ep.X - minrad, ep.Y)); if (toolong) // 横にはみ出るので台形にする { points.Add(new Point(sx, ep.Y)); if(xend != sp.X) points.Add(new Point(sx, (int)(ep.Y + (sp.Y - ep.Y) * (xend - sx) / w))); } else // 三角形にする { points.Add(new Point(xend, ep.Y)); } g.FillPolygon(dipBr, points.ToArray()); #endregion break; } } #endregion if (drawCenter) { #region center line foreach (Edge e in edges) { Point sp = e.StartPoint.Point; Point ep = e.EndPoint.Point; switch (e.Type) { case EdgeType.On: g.DrawLine(centerPen, sp, ep); break; case EdgeType.Off: case EdgeType.Dip: break; } } #endregion } } return bmp; }
public void SetLineCap_InvalidDashCap () { using (Pen p = new Pen (Brushes.Red)) { p.SetLineCap (LineCap.Flat, LineCap.Flat, (DashCap)Int32.MinValue); Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap"); Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap"); // invalid value was reseted to Flat (reported as FDBK50057) Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap"); } }
public override void Draw(System.Drawing.Graphics g) { base.Draw(g); if (Volume < 0) Volume = 0; if (Volume > ContentRectangle.Width) Volume = ContentRectangle.Width; using (Pen borderpen = new Pen(Color.FromArgb(139, 141, 144))) { borderpen.SetLineCap( LineCap.Round, LineCap.Round, DashCap.Round); lineRect = new Rectangle( base.ContentRectangle.X, base.ContentRectangle.Y + base.ContentRectangle.Height / 2 - 1, base.ContentRectangle.Width, 3); round = new RectangleF( Volume + base.ContentRectangle.X - 4.5f, lineRect.Y - 4.5f, 11, 11); //绘制 线性 白色底景 g.FillRectangle(new SolidBrush(Color.FromArgb(200, Color.White)), lineRect); g.DrawRectangle(borderpen, lineRect); //绘制播放进度线 Rectangle greedLine = new Rectangle( lineRect.X, lineRect.Y, (int)Volume, 3); g.FillRectangle(new SolidBrush(Color.FromArgb(200, 0, 130, 255)), greedLine); //g.DrawRectangle(new Pen(Color.FromArgb(48, 192, 136)), greedLine); g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.AntiAlias; if (antiTimer != null) { Bitmap bitmap = Resources.AnimateProgress; Bitmap comment = new Bitmap(368, 26); Graphics g2 = Graphics.FromImage(comment); g2.DrawImage(bitmap, new Rectangle(0, 0, 368, 26)); g2.Dispose(); Bitmap newbit = new Bitmap(46, 26); Graphics g1 = Graphics.FromImage(newbit); g1.DrawImage(comment, new Point(-position, 0)); g1.Dispose(); g.DrawImage(newbit, new PointF(round.X - 33.5f, round.Y - 22f)); newbit.Dispose(); bitmap.Dispose(); comment.Dispose(); } //绘制圆球 g.DrawEllipse(borderpen, round); //g.FillEllipse( // new LinearGradientBrush( // round, Color.FromArgb(255, Color.White), Color.FromArgb(255, Color.White), LinearGradientMode.Vertical), round); g.FillEllipse( new SolidBrush(Color.FromArgb(231, 232, 229)), round); if (_isHover) g.FillEllipse( new SolidBrush(Color.FromArgb(200, 190, 185)), round); if (_isDown) g.FillEllipse( new SolidBrush(Color.FromArgb(175, 185, 180)), round); } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (stage >= hanzi.BihuaBiao.Count) return; drawingPoint = e.Location; if (e.Button == MouseButtons.Left) { if (Math.Sqrt(Math.Pow(e.X - lastPoint.X, 2) + Math.Pow(e.Y - lastPoint.Y, 2)) > DrawSensitive) { Graphics g = Graphics.FromImage(drawTmp); g.SmoothingMode = SmoothingMode.AntiAlias; Pen p = new Pen(drawColor, (inkMode? drawingWidth * 2: penWidth)); p.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round); g.DrawLine(p, lastPoint, e.Location); drawLength += Math.Sqrt(Math.Pow(e.X - lastPoint.X, 2) + Math.Pow(e.Y - lastPoint.Y, 2)); lastPoint = e.Location; drawingWidth--; if (drawingWidth < DrawingWidthMin) drawingWidth = DrawingWidthMin; this.Refresh(); } if (stage < hanzi.BihuaBiao.Count && step < hanzi.BihuaBiao[stage].Gjdian.Count && Math.Sqrt(Math.Pow(e.X - hanzi.BihuaBiao[stage].Gjdian[step].X, 2) + Math.Pow(e.Y - hanzi.BihuaBiao[stage].Gjdian[step].Y, 2)) < DetectSensitive) { step++; } } }
private Pen MakePen(Color color, double strokeWidth, DStrokeStyle strokeStyle, DStrokeJoin strokeJoin, DStrokeCap strokeCap) { Pen p = new Pen(color, (float)strokeWidth); p.DashStyle = MakeDashStyle(strokeStyle); p.LineJoin = MakeLineJoin(strokeJoin); p.SetLineCap(MakeLineCap(strokeCap), MakeLineCap(strokeCap), DashCap.Flat); return p; }