本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.GraphicsPath.AddRectangle方法的具体用法?C# System.Drawing.Drawing2D.GraphicsPath.AddRectangle怎么用?C# System.Drawing.Drawing2D.GraphicsPath.AddRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了System.Drawing.Drawing2D.GraphicsPath.AddRectangle方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.FillMode = System.Drawing.Drawing2D.FillMode.Winding;
int height = TrackHeight / 5;
int nBars = this.Width / BarSpacing;
for (int bar = 0; bar < nBars; bar++)
{
gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, height, BarSpacing, height));
gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, height * 3, BarSpacing, height));
gp.AddRectangle(new System.Drawing.Rectangle(bar * BarSpacing, 0, BarWidth, TrackHeight));
}
e.Graphics.FillPath(System.Drawing.Brushes.SaddleBrown, gp);
}
示例2: CustomRect
public CustomRect(int x, int y, int width, Color color)
{
InitializeComponent();
this.Data = new XData();
this.Data.PointX = x;
this.Data.PointY = y;
this.Data.SizeX = width;
this.Data.SizeY = width;
this.Data.Width = width;
this.Data.Color = color;
System.Drawing.Drawing2D.GraphicsPath Button_Path = new System.Drawing.Drawing2D.GraphicsPath();
Button_Path.AddRectangle(new System.Drawing.Rectangle(this.Data.PointX, this.Data.PointY, this.Data.SizeX, this.Data.SizeY));
Region Button_Region = new Region(Button_Path);
this.Region = Button_Region;
Graphics g = this.CreateGraphics();
OnPaint(new PaintEventArgs(g, new System.Drawing.Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height)));
}
示例3: Transparent
public static System.Drawing.Drawing2D.GraphicsPath Transparent(Image im)
{
int x;
int y;
var bmp = new Bitmap(im);
var gp = new System.Drawing.Drawing2D.GraphicsPath();
var mask = bmp.GetPixel(0, 0);
for (x = 0; x <= bmp.Width - 1; x++)
{
for (y = 0; y <= bmp.Height - 1; y++)
{
if (!bmp.GetPixel(x, y).Equals(mask))
{
gp.AddRectangle(new Rectangle(x, y, 1, 1));
}
}
}
bmp.Dispose();
return gp;
}
示例4: RoundRectangle
private System.Drawing.Drawing2D.GraphicsPath RoundRectangle(Rectangle r, int radius, Corners corners)
{
//Make sure the Path fits inside the rectangle
r.Width -= 1;
r.Height -= 1;
//Scale the radius if it's too large to fit.
if (radius > (r.Width))
radius = r.Width;
if (radius > (r.Height))
radius = r.Height;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
if (radius <= 0)
path.AddRectangle(r);
else
if ((corners & Corners.TopLeft) == Corners.TopLeft)
path.AddArc(r.Left, r.Top, radius, radius, 180, 90);
else
path.AddLine(r.Left, r.Top, r.Left, r.Top);
if ((corners & Corners.TopRight) == Corners.TopRight)
path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90);
else
path.AddLine(r.Right, r.Top, r.Right, r.Top);
if ((corners & Corners.BottomRight) == Corners.BottomRight)
path.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90);
else
path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom);
if ((corners & Corners.BottomLeft) == Corners.BottomLeft)
path.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90);
else
path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom);
path.CloseFigure();
return path;
}
示例5: ToPoints
public List<Point> ToPoints(
float angle,
Rectangle rect)
{
// Create a GraphicsPath.
System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath();
path.AddRectangle(rect);
// Declare a matrix that will be used to rotate the text.
System.Drawing.Drawing2D.Matrix rotateMatrix =
new System.Drawing.Drawing2D.Matrix();
// Set the rotation angle and starting point for the text.
rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F));
// Transform the text with the matrix.
path.Transform(rotateMatrix);
List<Point> results = new List<Point>();
foreach(PointF p in path.PathPoints)
{
results.Add(new Point((int)p.X, (int)p.Y));
}
path.Dispose();
return results;
}
示例6: updateBorder
private void updateBorder()
{
var imeInfo = _monitor.IMEStatus;
_lastImeStatus = imeInfo;
if (imeInfo.WindowHandle == this.Handle || !imeInfo.WindowVisible || imeInfo.Ignored) {
this.Opacity = 0f;
setTopMost(false);
}
else {
var borderWidth = imeInfo.IMEEnabled ?
_settings.ImeOnBorderStyle.Width :
_settings.ImeOffBorderStyle.Width;
Rectangle windowRect = imeInfo.ClientBounds;
windowRect.Inflate(borderWidth, borderWidth);
// スクリーン外にはみ出た部分を押し込む
Rectangle screenRect = Screen.FromHandle(imeInfo.ClientHandle).Bounds;
{
int left = windowRect.X;
int top = windowRect.Y;
int right = windowRect.Right;
int bottom = windowRect.Bottom;
if (left < screenRect.X) left = screenRect.X;
if (top < screenRect.Y) top = screenRect.Y;
if (right > screenRect.Right) right = screenRect.Right;
if (bottom > screenRect.Bottom) bottom = screenRect.Bottom;
windowRect = Rectangle.FromLTRB(left, top, right, bottom);
}
if (this.Size == windowRect.Size) {
this.Location = windowRect.Location;
}
else {
var path = new System.Drawing.Drawing2D.GraphicsPath();
var w = windowRect.Width;
var h = windowRect.Height;
var border2x = borderWidth * 2;
path.AddPie(0, 0, border2x, border2x, 180, 90);
path.AddPie(w - border2x, 0, border2x, border2x, 270, 90);
path.AddPie(0, h - border2x, border2x, border2x, 90, 90);
path.AddPie(w - border2x, h - border2x, border2x, border2x, 0, 90);
path.AddRectangle(new Rectangle(0, borderWidth, borderWidth, h - border2x));
path.AddRectangle(new Rectangle(borderWidth, 0, w - border2x, borderWidth));
path.AddRectangle(new Rectangle(w - borderWidth, borderWidth, borderWidth, h - border2x));
path.AddRectangle(new Rectangle(borderWidth, h - borderWidth, w - border2x, borderWidth));
this.Region = new Region(path);
this.Bounds = windowRect;
}
this.BackColor = imeInfo.IMEEnabled ?
_settings.ImeOnBorderStyle.GetColor() :
_settings.ImeOffBorderStyle.GetColor();
this.Opacity = imeInfo.IMEEnabled ?
_settings.ImeOnBorderStyle.Opacity :
_settings.ImeOffBorderStyle.Opacity;
setTopMost(true);
}
}
示例7: DrawLabel
/// <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>
private static void DrawLabel(Graphics g, string labelText, RectangleF labelBounds, ILabelSymbolizer symb)
{
//Sets up the brushes and such for the labeling
Brush foreBrush = new SolidBrush(symb.FontColor);
Font textFont = symb.GetFont();
StringFormat format = new StringFormat();
format.Alignment = symb.Alignment;
Pen borderPen = new Pen(symb.BorderColor);
Brush backBrush = new SolidBrush(symb.BackColor);
Brush haloBrush = new SolidBrush(symb.HaloColor);
Pen haloPen = new Pen(symb.HaloColor);
haloPen.Width = 2;
haloPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Outset;
Brush shadowBrush = new SolidBrush(symb.DropShadowColor);
//Text graphics path
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddString(labelText, textFont.FontFamily, (int)textFont.Style, textFont.SizeInPoints * 96F / 72F, labelBounds, format);
//Draws the text outline
if (symb.BackColorEnabled && symb.BackColor != Color.Transparent)
{
if (symb.FontColor == Color.Transparent)
{
System.Drawing.Drawing2D.GraphicsPath backgroundGP = new System.Drawing.Drawing2D.GraphicsPath();
backgroundGP.AddRectangle(labelBounds);
backgroundGP.FillMode = System.Drawing.Drawing2D.FillMode.Alternate;
backgroundGP.AddPath(gp, true);
g.FillPath(backBrush, backgroundGP);
backgroundGP.Dispose();
}
else
{
g.FillRectangle(backBrush, labelBounds);
}
}
//Draws the border if its enabled
if (symb.BorderVisible && symb.BorderColor != Color.Transparent)
g.DrawRectangle(borderPen, labelBounds.X, labelBounds.Y, labelBounds.Width, labelBounds.Height);
//Draws the drop shadow
if (symb.DropShadowEnabled && symb.DropShadowColor != Color.Transparent)
{
System.Drawing.Drawing2D.Matrix gpTrans = new System.Drawing.Drawing2D.Matrix();
gpTrans.Translate(symb.DropShadowPixelOffset.X, symb.DropShadowPixelOffset.Y);
gp.Transform(gpTrans);
g.FillPath(shadowBrush, gp);
gpTrans = new System.Drawing.Drawing2D.Matrix();
gpTrans.Translate(-symb.DropShadowPixelOffset.X, -symb.DropShadowPixelOffset.Y);
gp.Transform(gpTrans);
}
//Draws the text halo
if (symb.HaloEnabled && symb.HaloColor != Color.Transparent)
g.DrawPath(haloPen, gp);
//Draws the text if its not transparent
if (symb.FontColor != Color.Transparent)
g.FillPath(foreBrush, gp);
//Cleans up the rest of the drawing objects
shadowBrush.Dispose();
borderPen.Dispose();
foreBrush.Dispose();
backBrush.Dispose();
haloBrush.Dispose();
haloPen.Dispose();
}
示例8: ResolveGraphicsPath
static System.Drawing.Drawing2D.GraphicsPath ResolveGraphicsPath(GraphicsPath path)
{
//convert from graphics path to internal presentation
System.Drawing.Drawing2D.GraphicsPath innerPath = path.InnerPath as System.Drawing.Drawing2D.GraphicsPath;
if (innerPath != null)
{
return innerPath;
}
//--------
innerPath = new System.Drawing.Drawing2D.GraphicsPath();
path.InnerPath = innerPath;
List<float> points;
List<PathCommand> cmds;
GraphicsPath.GetPathData(path, out points, out cmds);
int j = cmds.Count;
int p_index = 0;
for (int i = 0; i < j; ++i)
{
PathCommand cmd = cmds[i];
switch (cmd)
{
default:
throw new NotSupportedException();
case PathCommand.Arc:
innerPath.AddArc(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3],
points[p_index + 4],
points[p_index + 5]);
p_index += 6;
break;
case PathCommand.Bezier:
innerPath.AddBezier(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3],
points[p_index + 4],
points[p_index + 5],
points[p_index + 6],
points[p_index + 7]);
p_index += 8;
break;
case PathCommand.CloseFigure:
innerPath.CloseFigure();
break;
case PathCommand.Ellipse:
innerPath.AddEllipse(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]);
p_index += 4;
break;
case PathCommand.Line:
innerPath.AddLine(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]);
p_index += 4;
break;
case PathCommand.Rect:
innerPath.AddRectangle(
new System.Drawing.RectangleF(
points[p_index],
points[p_index + 1],
points[p_index + 2],
points[p_index + 3]));
p_index += 4;
break;
case PathCommand.StartFigure:
break;
}
}
return innerPath;
}
示例9: GetPath
protected System.Drawing.Drawing2D.GraphicsPath GetPath()
{
System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath();
if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D)
{
graphPath.AddRectangle(this.ClientRectangle);
}
else
{
try
{
int curve = 0;
System.Drawing.Rectangle rect = this.ClientRectangle;
int offset = 0;
if (this._BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle)
{
if (this._BorderWidth > 1)
{
offset = DoubleToInt(this.BorderWidth / 2);
}
curve = this.adjustedCurve;
}
else if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D)
{
}
else if (this._BorderStyle == System.Windows.Forms.BorderStyle.None)
{
curve = this.adjustedCurve;
}
if (curve == 0)
{
graphPath.AddRectangle(System.Drawing.Rectangle.Inflate(rect, -offset, -offset));
}
else
{
int rectWidth = rect.Width - 1 - offset;
int rectHeight = rect.Height - 1 - offset;
int curveWidth = 1;
if ((this._CurveMode & CornerCurveMode.TopRight) != 0)
{
curveWidth = (curve * 2);
}
else
{
curveWidth = 1;
}
graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90);
if ((this._CurveMode & CornerCurveMode.BottomRight) != 0)
{
curveWidth = (curve * 2);
}
else
{
curveWidth = 1;
}
graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90);
if ((this._CurveMode & CornerCurveMode.BottomLeft) != 0)
{
curveWidth = (curve * 2);
}
else
{
curveWidth = 1;
}
graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90);
if ((this._CurveMode & CornerCurveMode.TopLeft) != 0)
{
curveWidth = (curve * 2);
}
else
{
curveWidth = 1;
}
graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90);
graphPath.CloseFigure();
}
}
catch (System.Exception)
{
graphPath.AddRectangle(this.ClientRectangle);
}
}
return graphPath;
}
示例10: GetRoundedRect
/// <summary>
/// Creates a rounded corner rectangle from a regular rectangel
/// </summary>
/// <param name="baseRect"></param>
/// <param name="radius"></param>
/// <returns></returns>
private System.Drawing.Drawing2D.GraphicsPath GetRoundedRect(RectangleF baseRect, float radius)
{
if ((radius <= 0.0F) || radius >= ((Math.Min(baseRect.Width, baseRect.Height)) / 2.0))
{
System.Drawing.Drawing2D.GraphicsPath mPath = new System.Drawing.Drawing2D.GraphicsPath();
mPath.AddRectangle(baseRect);
mPath.CloseFigure();
return mPath;
}
float diameter = radius * 2.0F;
SizeF sizeF = new SizeF(diameter, diameter);
RectangleF arc = new RectangleF(baseRect.Location, sizeF);
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
// top left arc
path.AddArc(arc, 180, 90);
// top right arc
arc.X = baseRect.Right - diameter;
path.AddArc(arc, 270, 90);
// bottom right arc
arc.Y = baseRect.Bottom - diameter;
path.AddArc(arc, 0, 90);
// bottom left arc
arc.X = baseRect.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
示例11: ToGraphicsPath
/// <summary>
/// Converts this structure to a GraphicsPath object, used to draw to a Graphics device.
/// Consider that you can create a Region with a GraphicsPath object using one of the Region constructor.
/// </summary>
/// <returns></returns>
public System.Drawing.Drawing2D.GraphicsPath ToGraphicsPath()
{
if (mRectangle.IsEmpty)
return new System.Drawing.Drawing2D.GraphicsPath();
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
if (mRoundValue == 0)
{
//Remove 1 from height and width to draw the border in the right location
//path.AddRectangle(new Rectangle(new Point(mRectangle.X - 1, mRectangle.Y - 1), mRectangle.Size));
path.AddRectangle(mRectangle);
}
else
{
int x = mRectangle.X;
int y = mRectangle.Y;
int lineShift = 0;
int lineShiftX2 = 0;
//Basically the RoundValue is a percentage of the line to curve, so I simply multiply it with the lower side (height or width)
if (mRectangle.Height < mRectangle.Width)
{
lineShift = (int)((double)mRectangle.Height * mRoundValue);
lineShiftX2 = lineShift * 2;
}
else
{
lineShift = (int)((double)mRectangle.Width * mRoundValue);
lineShiftX2 = lineShift * 2;
}
//Top
path.AddLine(lineShift + x, 0 + y, (mRectangle.Width - lineShift) + x, 0 + y);
//Angle Top Right
path.AddArc((mRectangle.Width - lineShiftX2) + x, 0 + y,
lineShiftX2, lineShiftX2,
270, 90);
//Right
path.AddLine(mRectangle.Width + x, lineShift + y, mRectangle.Width + x, (mRectangle.Height - lineShift) + y);
//Angle Bottom Right
path.AddArc((mRectangle.Width - lineShiftX2) + x, (mRectangle.Height - lineShiftX2) + y,
lineShiftX2, lineShiftX2,
0, 90);
//Bottom
path.AddLine((mRectangle.Width - lineShift) + x, mRectangle.Height + y, lineShift + x, mRectangle.Height + y);
//Angle Bottom Left
path.AddArc(0 + x, (mRectangle.Height - lineShiftX2) + y,
lineShiftX2, lineShiftX2,
90, 90);
//Left
path.AddLine(0 + x, (mRectangle.Height - lineShift) + y, 0 + x, lineShift + y);
//Angle Top Left
path.AddArc(0 + x, 0 + y,
lineShiftX2, lineShiftX2,
180, 90);
}
return path;
}
示例12: GeneratePath
protected override void GeneratePath()
{
_Path = new System.Drawing.Drawing2D.GraphicsPath();
_Path.AddRectangle(new Rectangle(Location, Size));
InvalidationArea = Rectangle.Round(_Path.GetBounds());
}