本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddArc方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.AddArc方法的具体用法?C# GraphicsPath.AddArc怎么用?C# GraphicsPath.AddArc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath.AddArc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RoundRectangle
// paramters:
// pen 绘制边框。可以为null,那样就整体一个填充色,没有边框
// brush 绘制填充色。可以为null,那样就只有边框
public static void RoundRectangle(Graphics graphics,
Pen pen,
Brush brush,
float x,
float y,
float width,
float height,
float radius)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddLine(x + radius, y, x + width - (radius * 2), y);
path.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
path.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
path.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
path.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
path.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
path.AddLine(x, y + height - (radius * 2), x, y + radius);
path.AddArc(x, y, radius * 2, radius * 2, 180, 90);
path.CloseFigure();
if (brush != null)
graphics.FillPath(brush, path);
if (pen != null)
graphics.DrawPath(pen, path);
}
}
示例2: GetClone
private CustomLineCap GetClone(Pen pen, float size)
{
float endPoint;
endPoint = pen.Width == 0 ? 1 : size / pen.Width;
endPoint /= 2;
if (endPoint <= 0)
endPoint = 1e-3f;
GraphicsPath hPath = new GraphicsPath();
var r = endPoint / (2 * Math.Sin(_designAngle * (Math.PI / 180)));
var b = r - r * Math.Cos(_designAngle * (Math.PI / 180));
var h = endPoint / 2;
// Create the outline for our custom end cap.
hPath.AddArc(
(float)(-r - h), (float)(-b),
(float)(2 * r), (float)(2 * r),
(float)(-90 - _designAngle), (float)(2 * _designAngle));
hPath.AddArc(
(float)(h - r), (float)(b - 1.999999 * r),
(float)(2 * r), (float)(2 * r),
(float)(90 + _designAngle), (float)(-2 * _designAngle));
CustomLineCap clone = new CustomLineCap(null, hPath); // we set the stroke path only
clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
return clone;
}
示例3: DrawRoundRect
public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)
{
Y+=5;
X+=5;
width -= 12;
height -= 12;
GraphicsPath gp = new GraphicsPath();
gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);
gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));
gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);
gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);
gp.CloseFigure();
g.FillPath(Brushes.Transparent, gp);
gp.Dispose();
gp = new GraphicsPath();
gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);
gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));
gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);
gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);
gp.CloseFigure();
g.DrawPath(p, gp);
gp.Dispose();
}
示例4: DrawArc
public static void DrawArc(Rectangle re, GraphicsPath pa, int radius, EGroupPos _grouppos)
{
int radiusX0Y0 = radius,
radiusXfy0 = radius,
radiusX0Yf = radius,
radiusXfyf = radius;
switch (_grouppos)
{
case EGroupPos.Left:
radiusXfy0 = 1; radiusXfyf = 1;
break;
case EGroupPos.Center:
radiusX0Y0 = 1; radiusX0Yf = 1; radiusXfy0 = 1; radiusXfyf = 1;
break;
case EGroupPos.Right:
radiusX0Y0 = 1; radiusX0Yf = 1;
break;
case EGroupPos.Top:
radiusX0Yf = 1; radiusXfyf = 1;
break;
case EGroupPos.Bottom:
radiusX0Y0 = 1; radiusXfy0 = 1;
break;
}
pa.AddArc(re.X, re.Y, radiusX0Y0, radiusX0Y0, 180, 90);
pa.AddArc(re.Width - radiusXfy0, re.Y, radiusXfy0, radiusXfy0, 270, 90);
pa.AddArc(re.Width - radiusXfyf, re.Height - radiusXfyf, radiusXfyf, radiusXfyf, 0, 90);
pa.AddArc(re.X, re.Height - radiusX0Yf, radiusX0Yf, radiusX0Yf, 90, 90);
pa.CloseFigure();
}
示例5: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics G = e.Graphics;
LinearGradientBrush linearGradientBrush1 = new LinearGradientBrush(//创建线性渐变画刷
new Point(0, 0),new Point(20, 20), //渐变起始点和终止点
Color.Yellow,Color.Blue); //渐变起始颜色和终止颜色
G.FillRectangle(linearGradientBrush1, new Rectangle(0, 0, 150, 150));//绘制矩形
LinearGradientBrush linearGradientBrush2 = new LinearGradientBrush(//创建线性渐变画刷
new Rectangle(0, 0, 20, 20), //渐变所在矩形
Color.Yellow, Color.Blue, 60f); //渐变起始颜色、终止颜色以及渐变方向
linearGradientBrush2.WrapMode = WrapMode.TileFlipXY;
G.FillRectangle(linearGradientBrush2, new Rectangle(150, 0, 150, 150));//绘制矩形
GraphicsPath graphicsPath1 = new GraphicsPath(); //创建绘制路径
graphicsPath1.AddArc(new Rectangle(0, 150, 100, 100), 90, 180);//向路径中添加半左圆弧
graphicsPath1.AddArc(new Rectangle(150, 150, 100, 100), 270, 180);//向路径中添加半右圆弧
graphicsPath1.CloseFigure(); //闭合路径
PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath1);//创建路径渐变画刷
pathGradientBrush.CenterColor = Color.Yellow; //指定画刷中心颜色
pathGradientBrush.SurroundColors = new Color[] { Color.Blue };//指定画刷周边颜色
pathGradientBrush.CenterPoint = new PointF(125, 200); //指定画刷中心点坐标
G.SmoothingMode = SmoothingMode.AntiAlias; //消锯齿
G.FillPath(pathGradientBrush, graphicsPath1); //利用画刷填充路径
G.DrawPath(new Pen(Color.Lime, 3f), graphicsPath1); //绘制闭合路径曲线
linearGradientBrush1.Dispose();
linearGradientBrush2.Dispose();
graphicsPath1.Dispose();
pathGradientBrush.Dispose();
}
示例6: CreateRoundedRectanglePath
// Create a rounded rectangle path with a given Rectangle and a given corner Diameter
public static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, float diameter)
{
GraphicsPath path = new GraphicsPath ();
RectangleF arcrect = new RectangleF (rect.Location, new SizeF (diameter, diameter));
// Top left arc
path.AddArc (arcrect, 190, 90);
path.AddLine (rect.Left + (int)(diameter / 2), rect.Top, rect.Left + rect.Width - (int)(diameter / 2), rect.Top);
// Top right arc
arcrect.X = rect.Right - diameter;
path.AddArc (arcrect, 270, 90);
path.AddLine (rect.Left + rect.Width, rect.Top + (int)(diameter / 2), rect.Left + rect.Width, rect.Top + rect.Height - (int)(diameter / 2));
// Bottom right arc
arcrect.Y = rect.Bottom - diameter;
path.AddArc (arcrect, 0, 90);
// Bottom left arc
arcrect.X = rect.Left;
path.AddArc (arcrect, 90, 90);
path.CloseFigure ();
return path;
}
示例7: CreateCompleteTabPath
public GraphicsPath CreateCompleteTabPath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
int corner = 6;
int rightOffset = 1;
path.AddLine(
r.Left, r.Bottom,
r.Left, r.Top + corner);
path.AddArc(
new Rectangle(
r.Left, r.Top,
corner, corner),
180, 90);
path.AddLine(
r.Left + corner, r.Top,
r.Right - corner - rightOffset, r.Top);
path.AddArc(
new Rectangle(
r.Right - corner - rightOffset, r.Top,
corner, corner),
-90, 90);
path.AddLine(
r.Right - rightOffset, r.Top + corner,
r.Right - rightOffset, r.Bottom);
path.CloseFigure();
return path;
}
示例8: CreateRoundedRectangle
public static GraphicsPath CreateRoundedRectangle(SizeF size, PointF location)
{
int cornerSize = (int)GraphConstants.CornerSize * 2;
int connectorSize = (int)GraphConstants.ConnectorSize;
int halfConnectorSize = (int)Math.Ceiling(connectorSize / 2.0f);
var height = size.Height;
var width = size.Width;
var halfWidth = width / 2.0f;
var halfHeight = height / 2.0f;
var connectorOffset = (int)Math.Floor((GraphConstants.MinimumItemHeight - GraphConstants.ConnectorSize) / 2.0f);
var left = location.X;
var top = location.Y;
var right = location.X + width;
var bottom = location.Y + height;
var path = new GraphicsPath(FillMode.Winding);
path.AddArc(left, top, cornerSize, cornerSize, 180, 90);
path.AddArc(right - cornerSize, top, cornerSize, cornerSize, 270, 90);
path.AddArc(right - cornerSize, bottom - cornerSize, cornerSize, cornerSize, 0, 90);
path.AddArc(left, bottom - cornerSize, cornerSize, cornerSize, 90, 90);
path.CloseFigure();
return path;
}
示例9: Round
/// <summary>
/// 圆角代码
/// </summary>
public void Round()
{
GraphicsPath oPath = new GraphicsPath();
const int x = 0;
const int y = 0;
int thisWidth = this.Width;
int thisHeight = this.Height;
int angle = _radius;
if (angle > 0)
{
oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
oPath.CloseAllFigures();
Region = new System.Drawing.Region(oPath);
}
else
{
oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
oPath.CloseAllFigures();
Region = new System.Drawing.Region(oPath);
}
}
示例10: DrawRoundedRectangle
/// <summary>
/// Draws a rounded rectangle on a bitmap
/// </summary>
/// <param name="Image">Image to draw on</param>
/// <param name="BoxColor">The color that the box should be</param>
/// <param name="XPosition">The upper right corner's x position</param>
/// <param name="YPosition">The upper right corner's y position</param>
/// <param name="Height">Height of the box</param>
/// <param name="Width">Width of the box</param>
/// <param name="CornerRadius">Radius of the corners</param>
/// <returns>The bitmap with the rounded box on it</returns>
public static Bitmap DrawRoundedRectangle(Bitmap Image, Color BoxColor, int XPosition, int YPosition,
int Height, int Width, int CornerRadius)
{
Bitmap NewBitmap = new Bitmap(Image, Image.Width, Image.Height);
using (Graphics NewGraphics = Graphics.FromImage(NewBitmap))
{
using (Pen BoxPen = new Pen(BoxColor))
{
using (GraphicsPath Path = new GraphicsPath())
{
Path.AddLine(XPosition + CornerRadius, YPosition, XPosition + Width - (CornerRadius * 2), YPosition);
Path.AddArc(XPosition + Width - (CornerRadius * 2), YPosition, CornerRadius * 2, CornerRadius * 2, 270, 90);
Path.AddLine(XPosition + Width, YPosition + CornerRadius, XPosition + Width, YPosition + Height - (CornerRadius * 2));
Path.AddArc(XPosition + Width - (CornerRadius * 2), YPosition + Height - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 0, 90);
Path.AddLine(XPosition + Width - (CornerRadius * 2), YPosition + Height, XPosition + CornerRadius, YPosition + Height);
Path.AddArc(XPosition, YPosition + Height - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 90, 90);
Path.AddLine(XPosition, YPosition + Height - (CornerRadius * 2), XPosition, YPosition + CornerRadius);
Path.AddArc(XPosition, YPosition, CornerRadius * 2, CornerRadius * 2, 180, 90);
Path.CloseFigure();
NewGraphics.DrawPath(BoxPen, Path);
}
}
}
return NewBitmap;
}
示例11: DrawRoundedRectangle
public static void DrawRoundedRectangle(Graphics newGraphics, Color boxColor, Color gradFillColor1, Color gradFillColor2, int xPosition, int yPosition,
int height, int width, int cornerRadius)
{
using (var boxPen = new Pen(boxColor))
{
using (var path = new GraphicsPath())
{
path.AddLine(xPosition + cornerRadius, yPosition, xPosition + width - (cornerRadius * 2), yPosition);
path.AddArc(xPosition + width - (cornerRadius * 2), yPosition, cornerRadius * 2, cornerRadius * 2, 270, 90);
path.AddLine(xPosition + width, yPosition + cornerRadius, xPosition + width,
yPosition + height - (cornerRadius * 2));
path.AddArc(xPosition + width - (cornerRadius * 2), yPosition + height - (cornerRadius * 2), cornerRadius * 2,
cornerRadius * 2, 0, 90);
path.AddLine(xPosition + width - (cornerRadius * 2), yPosition + height, xPosition + cornerRadius,
yPosition + height);
path.AddArc(xPosition, yPosition + height - (cornerRadius * 2), cornerRadius * 2, cornerRadius * 2, 90, 90);
path.AddLine(xPosition, yPosition + height - (cornerRadius * 2), xPosition, yPosition + cornerRadius);
path.AddArc(xPosition, yPosition, cornerRadius * 2, cornerRadius * 2, 180, 90);
path.CloseFigure();
newGraphics.DrawPath(boxPen, path);
var b = new LinearGradientBrush(new Point(xPosition, yPosition),
new Point(xPosition + width, yPosition + height), gradFillColor1,
gradFillColor2);
newGraphics.FillPath(b, path);
}
}
}
示例12: GenerateCapsule
private static GraphicsPath GenerateCapsule( this Graphics graphics, RectangleF rectangle ) {
float diameter;
RectangleF arc;
GraphicsPath path = new GraphicsPath();
try {
if( rectangle.Width > rectangle.Height ) {
diameter = rectangle.Height;
SizeF sizeF = new SizeF( diameter, diameter );
arc = new RectangleF( rectangle.Location, sizeF );
path.AddArc( arc, 90, 180 );
arc.X = rectangle.Right - diameter;
path.AddArc( arc, 270, 180 );
} else if( rectangle.Width < rectangle.Height ) {
diameter = rectangle.Width;
SizeF sizeF = new SizeF( diameter, diameter );
arc = new RectangleF( rectangle.Location, sizeF );
path.AddArc( arc, 180, 180 );
arc.Y = rectangle.Bottom - diameter;
path.AddArc( arc, 0, 180 );
} else
path.AddEllipse( rectangle );
} catch { path.AddEllipse( rectangle ); } finally { path.CloseFigure(); }
return path;
}
示例13: CreateRoundedRectanglePath
public static GraphicsPath CreateRoundedRectanglePath(RectangleF rect, float radius)
{
GraphicsPath path = new GraphicsPath();
if (rect.Width <= 0.0f || rect.Height <= 0.0f) return path;
float x1 = rect.X;
float x2 = rect.X + rect.Width;
float y1 = rect.Y;
float y2 = rect.Y + rect.Height;
if (radius > rect.Width / 2) radius = rect.Width / 2;
if (radius > rect.Height / 2) radius = rect.Width / 2;
// Top left arc and top edge:
if (radius > 0.0) path.AddArc(new RectangleF(x1, y1, radius * 2, radius * 2), 180, 90);
path.AddLine(x1 + radius, y1, x2 - radius, y1);
// Top right arc and right edge:
if (radius > 0.0) path.AddArc(new RectangleF(x2 - radius * 2, y1, radius * 2, radius * 2), 270, 90);
path.AddLine(x2, y1 + radius, x2, y2 - radius);
// Bottom right arc and bottom edge:
if (radius > 0.0) path.AddArc(new RectangleF(x2 - radius * 2, y2 - radius * 2, radius * 2, radius * 2), 0, 90);
path.AddLine(x2 - radius, y2, x1 + radius, y2);
// Bottom left arc and left edge:
if (radius > 0.0) path.AddArc(new RectangleF(x1, y2 - radius * 2, radius * 2, radius * 2), 90, 90);
path.AddLine(x1, y2 - radius, x1, y1 + radius);
return path;
}
示例14: Form1_Paint
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
//Создаем массив точек
Point[] points = {
new Point(5, 10),
new Point(23, 130),
new Point(130, 57)};
GraphicsPath path = new GraphicsPath();
//рисуем первую траекторию
path.StartFigure();
path.AddEllipse(170, 170, 100, 50);
// заливаем траекторию цветом
g.FillPath(Brushes.Aqua, path);
//рисуем вторую траекторию
path.StartFigure();
path.AddCurve(points, 0.5F);
path.AddArc(100, 50, 100, 100, 0, 120);
path.AddLine(50, 150, 50, 220);
// Закрываем траекторию
path.CloseFigure();
//рисуем четвертую траекторию
path.StartFigure();
path.AddArc(180, 30, 60, 60, 0, -170);
g.DrawPath(new Pen(Color.Blue, 3), path);
g.Dispose();
}
示例15: Draw
public override void Draw(Graphics g)
{
System.Drawing.Size st = g.MeasureString(Marker.ToolTipText, Font).ToSize();
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height, st.Width + TextPadding.Width, st.Height + TextPadding.Height);
rect.Offset(Offset.X, Offset.Y);
using(GraphicsPath objGP = new GraphicsPath())
{
objGP.AddLine(rect.X + 2 * Radius, rect.Y + rect.Height, rect.X + Radius, rect.Y + rect.Height + Radius);
objGP.AddLine(rect.X + Radius, rect.Y + rect.Height + Radius, rect.X + Radius, rect.Y + rect.Height);
objGP.AddArc(rect.X, rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 90, 90);
objGP.AddLine(rect.X, rect.Y + rect.Height - (Radius * 2), rect.X, rect.Y + Radius);
objGP.AddArc(rect.X, rect.Y, Radius * 2, Radius * 2, 180, 90);
objGP.AddLine(rect.X + Radius, rect.Y, rect.X + rect.Width - (Radius * 2), rect.Y);
objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y, Radius * 2, Radius * 2, 270, 90);
objGP.AddLine(rect.X + rect.Width, rect.Y + Radius, rect.X + rect.Width, rect.Y + rect.Height - (Radius * 2));
objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 0, 90); // Corner
objGP.CloseFigure();
g.FillPath(Fill, objGP);
g.DrawPath(Stroke, objGP);
}
#if !PocketPC
g.DrawString(Marker.ToolTipText, Font, Brushes.Navy, rect, Format);
#else
g.DrawString(ToolTipText, ToolTipFont, TooltipForeground, rect, ToolTipFormat);
#endif
}