本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddBeziers方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.AddBeziers方法的具体用法?C# GraphicsPath.AddBeziers怎么用?C# GraphicsPath.AddBeziers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath.AddBeziers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBeziersExample
private void AddBeziersExample(PaintEventArgs e, Point[] myArray)
{
// Adds two Bezier curves.
//Point[] myArray =
// {
// new Point(20, 100),
// new Point(40, 75),
// new Point(60, 125),
// new Point(80, 100),
// new Point(100, 50),
// new Point(120, 150),
// new Point(140, 100)
// };
// Create the path and add the curves.
GraphicsPath myPath = new GraphicsPath();
myPath.AddBeziers(myArray);
// Draw the path to the screen.
Pen myPen = new Pen(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
示例2: OnRendererTabPageItem
public override void OnRendererTabPageItem(Graphics gfx, Rectangle tabPageItemRct, string tabPageText, int index, CommonObjects.ButtonState btnState)
{
Rectangle itemRct = tabPageItemRct;
SmoothingMode mode = gfx.SmoothingMode;
gfx.SmoothingMode = SmoothingMode.AntiAlias;
using (StringFormat format = new StringFormat(StringFormatFlags.LineLimit))
{
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
using (GraphicsPath path = new GraphicsPath())
{
bool isSelected = false;
Color textColor = DisabledTabPageItemForeColor;
switch (btnState)
{
case CommonObjects.ButtonState.Hover:
case CommonObjects.ButtonState.Normal:
textColor = TabPageItemForeColor;
goto case CommonObjects.ButtonState.Disabled;
case CommonObjects.ButtonState.Pressed:
isSelected = true;
textColor = SelectedTabPageItemForeColor;
using (Brush brush = new SolidBrush(BackColor))
gfx.FillRectangle(brush, tabPageItemRct.Left - 1, tabPageItemRct.Top - 1, tabPageItemRct.Width + 1, tabPageItemRct.Height + 1);
goto case CommonObjects.ButtonState.Disabled;
case CommonObjects.ButtonState.Disabled:
int xOffset;
if (index == 0)
{
xOffset = itemRct.Left + 10 + (itemRct.Height / 2);
Point[] points = new Point[]
{
new Point(itemRct.Left, itemRct.Bottom),
new Point(itemRct.Left, itemRct.Bottom - 4),
new Point(itemRct.Left + 2, itemRct.Bottom - 11),
new Point(xOffset, itemRct.Top),
};
path.AddBeziers(points);
}
else if (isSelected)
{
xOffset = itemRct.Left + (itemRct.Height / 2);
Point[] points = new Point[]
{
new Point(itemRct.Left - 10, itemRct.Bottom),
new Point(itemRct.Left - 10, itemRct.Bottom - 4),
new Point(itemRct.Left - 8, itemRct.Bottom - 11),
new Point(xOffset, itemRct.Top),
};
path.AddBeziers(points);
}
else
{
xOffset = itemRct.Left + (itemRct.Height / 2);
path.AddLine(itemRct.Left, itemRct.Bottom, itemRct.Left,
itemRct.Top + (itemRct.Height / 2) - 3);
Point[] points = new Point[]
{
new Point(itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 4),
new Point(itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 5),
new Point(itemRct.Left + 2, itemRct.Top + 2),
new Point(xOffset, itemRct.Top),
};
path.AddBeziers(points);
}
path.AddLine(xOffset + 1, itemRct.Top, itemRct.Right - 5, itemRct.Top);
path.AddLine(itemRct.Right - 1, itemRct.Top + 2, itemRct.Right - 1, itemRct.Bottom);
path.CloseFigure();
using (LinearGradientBrush brush = new LinearGradientBrush(itemRct, Color.FromArgb(248, 247, 242),
isSelected ? Color.White : Color.FromArgb(233, 233, 216), LinearGradientMode.Vertical))
{
Blend bl = new Blend(2);
bl.Factors = new float[] { 0.4F, 1.0F };
bl.Positions = new float[] { 0.0F, 1.0F };
brush.Blend = bl;
gfx.FillPath(brush, path);
}
using (Pen pen = new Pen(SystemColors.ControlDark))
{
gfx.DrawPath(pen, path);
if(isSelected)
{
pen.Color = Color.White;
gfx.DrawLine(pen, index == 0 ? itemRct.Left + 1 : itemRct.Left - 9, itemRct.Bottom, itemRct.Right - 2, itemRct.Bottom);
}
}
using (Font font = new Font(NeoTabPageItemsFont, isSelected ? FontStyle.Bold : FontStyle.Regular))
{
itemRct.X += 2;
itemRct.Width -= 2;
itemRct.Y += 2;
itemRct.Height -= 2;
if (index == 0)
{
itemRct.X += 6;
itemRct.Width -= 6;
}
using (Brush brush = new SolidBrush(textColor))
gfx.DrawString(tabPageText, font, brush, itemRct, format);
//.........这里部分代码省略.........
示例3: DrawBeziers
public void DrawBeziers (Pen pen, PointF [] points) {
GraphicsPath path = new GraphicsPath();
path.AddBeziers(points);
DrawPath(pen, path);
}
示例4: GetArrowLinePoints
static List<PointF> GetArrowLinePoints(float x1, float y1, float x2, float y2, out float centerX, out float centerY, float extra_thickness = 0)
{
var widthX = (x2 - x1);
var lengthX = Math.Max(60, Math.Abs(widthX / 2))
//+ Math.Max(0, -widthX / 2)
;
var lengthY = 0;// Math.Max(-170, Math.Min(-120.0f, widthX - 120.0f)) + 120.0f;
if (widthX < 120)
lengthX = 60;
var yB = ((y1 + y2) / 2) + lengthY;// (y2 + ((y1 - y2) / 2) * 0.75f) + lengthY;
var yC = y2 + yB;
var xC = (x1 + x2) / 2;
var xA = x1 + lengthX;
var xB = x2 - lengthX;
/*
if (widthX >= 120)
{
xA = xB = xC = x2 - 60;
}
//*/
var points = new List<PointF> {
new PointF(x1, y1),
new PointF(xA, y1),
new PointF(xB, y2),
new PointF(x2 - GraphConstants.ConnectorSize - extra_thickness, y2)
};
var t = 1.0f;//Math.Min(1, Math.Max(0, (widthX - 30) / 60.0f));
var yA = (yB * t) + (yC * (1 - t));
if (widthX <= 120)
{
points.Insert(2, new PointF(xB, yA));
points.Insert(2, new PointF(xC, yA));
points.Insert(2, new PointF(xA, yA));
}
//*
using (var tempPath = new GraphicsPath())
{
tempPath.AddBeziers(points.ToArray());
tempPath.Flatten();
points = tempPath.PathPoints.ToList();
}
//*/
var angles = new PointF[points.Count - 1];
var lengths = new float[points.Count - 1];
float totalLength = 0;
centerX = 0;
centerY = 0;
points.Add(points[points.Count - 1]);
for (int i = 0; i < points.Count - 2; i++)
{
var pt1 = points[i];
var pt2 = points[i + 1];
var pt3 = points[i + 2];
var deltaX = (float)((pt2.X - pt1.X) + (pt3.X - pt2.X));
var deltaY = (float)((pt2.Y - pt1.Y) + (pt3.Y - pt2.Y));
var length = (float)Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));
if (length <= 1.0f)
{
points.RemoveAt(i);
i--;
continue;
}
lengths[i] = length;
totalLength += length;
angles[i].X = deltaX / length;
angles[i].Y = deltaY / length;
}
float midLength = (totalLength / 2.0f);// * 0.75f;
float startWidth = extra_thickness + 0.75f;
float endWidth = extra_thickness + (GraphConstants.ConnectorSize / 3.5f);
float currentLength = 0;
var newPoints = new List<PointF>();
newPoints.Add(points[0]);
for (int i = 0; i < points.Count - 2; i++)
{
var angle = angles[i];
var point = points[i + 1];
var length = lengths[i];
var width = (((currentLength * (endWidth - startWidth)) / totalLength) + startWidth);
var angleX = angle.X * width;
var angleY = angle.Y * width;
var newLength = currentLength + length;
if (currentLength <= midLength &&
newLength >= midLength)
{
var dX = point.X - points[i].X;
var dY = point.Y - points[i].Y;
var t1 = midLength - currentLength;
var l = length;
centerX = points[i].X + ((dX * t1) / l);
centerY = points[i].Y + ((dY * t1) / l);
}
//.........这里部分代码省略.........
示例5: AddBeziers_SamePointF
public void AddBeziers_SamePointF ()
{
PointF[] points = new PointF [4] { new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f) };
GraphicsPath gp = new GraphicsPath ();
gp.AddBeziers (points);
// all points are present
Assert.AreEqual (4, gp.PointCount, "1-PointCount");
Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]");
Assert.AreEqual (3, gp.PathTypes [1], "1-PathTypes[1]");
Assert.AreEqual (3, gp.PathTypes [2], "1-PathTypes[2]");
Assert.AreEqual (3, gp.PathTypes [3], "1-PathTypes[3]");
gp.AddBeziers (points);
// the first point (move to) can be compressed (i.e. removed)
Assert.AreEqual (7, gp.PointCount, "2-PointCount");
Assert.AreEqual (3, gp.PathTypes [4], "2-PathTypes[4]");
Assert.AreEqual (3, gp.PathTypes [5], "2-PathTypes[5]");
Assert.AreEqual (3, gp.PathTypes [6], "2-PathTypes[6]");
}
示例6: AddBeziers_3_PointFs
public void AddBeziers_3_PointFs ()
{
GraphicsPath gp = new GraphicsPath ();
gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
}
示例7: AddBeziers_3_Points
public void AddBeziers_3_Points ()
{
GraphicsPath gp = new GraphicsPath ();
gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
}
示例8: DrawPath
//Code to draw path for the line
public override void DrawPath()
{
if (Container == null) return;
if (ControlPoints == null) return;
//Get the start and end location depending on start shapes etc
PointF startLocation = GetOriginLocation(Start,End);
PointF endLocation = GetOriginLocation(End,Start);
//Add the points to the solution
ArrayList points = new ArrayList();
points.Add(startLocation);
//Add the control points
//If bezier must be 2,5,8 control points etc
PointF[] controlPoints;
//Set up control points
if (CurveType == CurveType.Bezier)
{
//Must be 2, 5, 8 etc
if (mControlPoints.GetUpperBound(0) < 1) throw new CurveException("Bezier must contain at least 2 control points.");
int intMax = (((int) (mControlPoints.GetUpperBound(0) - 1) / 3) * 3) + 2;
controlPoints = new PointF[intMax];
for (int i = 0; i < intMax; i++ )
{
controlPoints[i] = mControlPoints[i];
}
}
else
{
controlPoints = mControlPoints;
}
points.InsertRange(1,controlPoints);
//Add the end points
points.Add(endLocation);
//Draw the path
GraphicsPath path = new GraphicsPath();
if (CurveType == CurveType.Bezier)
{
path.AddBeziers((PointF[]) points.ToArray(typeof(PointF)));
}
else
{
path.AddCurve((PointF[]) points.ToArray(typeof(PointF)),Tension);
}
SetPoints(points);
//Calculate path rectangle
RectangleF rect = path.GetBounds();
SetRectangle(rect); //Sets the bounding rectangle
SetPath(path); //setpath moves the line to 0,0
}
示例9: getOutlinePoly
internal override PointCollection getOutlinePoly()
{
PointCollection poly = new PointCollection(0);
GraphicsPath arrowPath = new GraphicsPath(FillMode.Alternate);
// draw the arrow's line
if (style == ArrowStyle.Bezier)
{
arrowPath.AddBeziers(points.getArray());
}
else
{
arrowPath.AddLines(points.getArray());
}
System.Drawing.Pen widenPen = new System.Drawing.Pen(Color.Black,
2 * Constants.getMillimeter(flowChart.MeasureUnit));
arrowPath.Widen(widenPen);
arrowPath.Flatten();
poly.AddRange(arrowPath.PathPoints);
widenPen.Dispose();
arrowPath.Dispose();
return poly;
}
示例10: Draw
public void Draw(Graphics g, System.Drawing.Color color)
{
switch (kind) {
case SymbolStrokes.Disc:
using (Brush b = new SolidBrush(color))
g.FillEllipse(b, new RectangleF(points[0].X - radius, points[0].Y - radius, radius * 2, radius * 2));
break;
case SymbolStrokes.Circle:
try {
using (Pen p = new Pen(color, thickness))
g.DrawEllipse(p, new RectangleF(points[0].X - radius, points[0].Y - radius, radius * 2, radius * 2));
}
catch (ExternalException) {
// Ignore this exeption. Not sure what causes it.
}
break;
case SymbolStrokes.Polyline:
using (Pen p = new Pen(color, thickness)) {
p.LineJoin = corners;
p.StartCap = ends;
p.EndCap = ends;
g.DrawLines(p, points);
}
break;
case SymbolStrokes.Polygon:
using (Pen p = new Pen(color, thickness)) {
p.LineJoin = corners;
g.DrawPolygon(p, points);
}
break;
case SymbolStrokes.FilledPolygon:
using (Brush b = new SolidBrush(color))
g.FillPolygon(b, points);
break;
case SymbolStrokes.PolyBezier:
using (Pen p = new Pen(color, thickness)) {
p.StartCap = ends;
p.EndCap = ends;
g.DrawBeziers(p, points);
}
break;
case SymbolStrokes.FilledPolyBezier:
using (Brush b = new SolidBrush(color))
using (GraphicsPath path = new GraphicsPath()) {
path.AddBeziers(points);
g.FillPath(b, path);
}
break;
default:
Debug.Fail("Bad SymbolStroke kind");
break;
}
}
示例11: updateText
/// <summary>
/// Updates the arrow's text.
/// </summary>
private void updateText()
{
if (textStyle == ArrowTextStyle.Follow)
{
textLayout = new TextLayout();
PointF[] poly = points.getArray();
if (style == ArrowStyle.Bezier)
{
GraphicsPath temp = new GraphicsPath();
temp.AddBeziers(poly);
temp.Flatten(new Matrix(), 1f);
poly = temp.PathPoints;
temp.Dispose();
}
// Check whether to reverse the arrow points
if (poly[0].X > poly[poly.Length - 1].X)
{
for (int i = 0; i < poly.Length / 2; i++)
{
PointF t = poly[i];
poly[i] = poly[poly.Length - i - 1];
poly[poly.Length - i - 1] = t;
}
}
Graphics graphics = flowChart.CreateGraphics();
flowChart.setTransforms(graphics);
float textHeight = Font.GetHeight(graphics);
PointF startPoint = poly[0];
for (int i = 0; i < poly.Length - 1; i++)
{
// The processed segment
PointF p = poly[i];
PointF t = poly[i + 1];
float a = 0;
float r = 0;
GeoConvert.DekartToPolar(t, p, ref a, ref r);
// Find the angle between the segments
float angle = 0;
// The angle for the last segment remains 0
float a2 = 0;
float r2 = 0;
if (i < poly.Length - 2)
{
// The next segment
PointF p2 = poly[i + 1];
PointF t2 = poly[i + 2];
GeoConvert.DekartToPolar(p2, t2, ref a2, ref r2);
if (a2 < a)
a2 += 360;
angle = a2 - a;
}
// Calculate the real length (the start point might have been offset)
float rr = 0;
float aa = 0;
GeoConvert.DekartToPolar(startPoint, t, ref aa, ref rr);
PointF d1 = startPoint;
PointF d2 = t;
PointF d3 = PointF.Empty;
PointF d4 = PointF.Empty;
float width = 0;
if (angle < 180)
{
// No restrictions
GeoConvert.PolarToDekart(d1, a - 90, textHeight, ref d4);
GeoConvert.PolarToDekart(d2, a - 90, textHeight, ref d3);
width = rr;
startPoint = t;
}
else
{
GeoConvert.PolarToDekart(d1, a - 90, textHeight, ref d4);
float alpha2 = (360 - angle) / 2;
float xx = textHeight / (float)Math.Sin(Rad(alpha2));
float xxProj = (float)Math.Sqrt(Math.Pow(xx, 2) - Math.Pow(textHeight, 2));
if (xxProj > rr)
{
xxProj = rr;
xx = (float)Math.Sqrt(Math.Pow(xxProj, 2) + Math.Pow(textHeight, 2));
}
//.........这里部分代码省略.........
示例12: AddBeziers_PointFArr
public void AddBeziers_PointFArr()
{
PointF [] points = new PointF [] { new PointF(20.01f, 100.1f),
new PointF(40.02f, 75.2f),
new PointF(60.03f, 125.3f),
new PointF(80.04f, 100.4f),
new PointF(100.05f, 50.5f),
new PointF(120.06f, 150.6f),
new PointF(140.07f, 100.7f)};
path = new GraphicsPath();
path.AddBeziers(points);
Assert.AreEqual (7, path.PointCount);
PointF [] expectedPoints = new PointF [] { new PointF(20.01f, 100.1f),
new PointF(40.02f, 75.2f),
new PointF(60.03f, 125.3f),
new PointF(80.04f, 100.4f),
new PointF(100.05f, 50.5f),
new PointF(120.06f, 150.6f),
new PointF(140.07f, 100.7f)};
for(int i = 0; i < path.PointCount; i++) {
DrawingTest.AssertAlmostEqual(expectedPoints [i], path.PathPoints [i]);
}
byte [] expectedTypes = new byte [] { (byte) PathPointType.Start,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3};
for (int i=0; i < expectedTypes.Length; i++) {
Assert.AreEqual (expectedTypes [i], path.PathTypes [i]);
}
t.Graphics.DrawPath (p, path);
t.Show ();
//t.AssertCompare ();
}
示例13: AddBeziers_PointArr
public void AddBeziers_PointArr()
{
Point [] points = new Point [] {new Point(20, 100),
new Point(40, 75),
new Point(60, 125),
new Point(80, 100),
new Point(100, 50),
new Point(120, 150),
new Point(140, 100)};
path = new GraphicsPath();
path.AddBeziers(points);
Assert.AreEqual (7, path.PointCount);
PointF [] expectedPoints = new PointF [] { new PointF(20f, 100f),
new PointF(40f, 75f),
new PointF(60f, 125f),
new PointF(80f, 100f),
new PointF(100f, 50f),
new PointF(120f, 150f),
new PointF(140f, 100f)};
for(int i = 0; i < path.PointCount; i++) {
DrawingTest.AssertAlmostEqual(expectedPoints [i], path.PathPoints [i]);
}
byte [] expectedTypes = new byte [] { (byte) PathPointType.Start,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3,
(byte) PathPointType.Bezier3};
for (int i=0; i < expectedTypes.Length; i++) {
Assert.AreEqual (expectedTypes [i], path.PathTypes [i]);
}
t.Graphics.DrawPath (p, path);
t.Show ();
//t.AssertCompare ();
}
示例14: StartClose_AddBeziers
public void StartClose_AddBeziers ()
{
GraphicsPath path = new GraphicsPath ();
path.AddLine (1, 1, 2, 2);
path.AddBeziers (new Point[7] { new Point (10, 10),
new Point (20, 10), new Point (20, 20), new Point (30, 20),
new Point (40, 40), new Point (50, 40), new Point (50, 50)
});
path.AddLine (10, 10, 20, 20);
byte[] types = path.PathTypes;
// check first types
Assert.AreEqual (0, types[0], "start/Line");
Assert.AreEqual (1, types[2], "start/Bezier");
// check last types
Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
}
示例15: DrawBeziers
public void DrawBeziers(Pen pen, PointF[] points)
{
using (var path = new GraphicsPath())
{
path.AddBeziers(points);
DrawPath(pen, path);
}
}