本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.AddRoundedRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.AddRoundedRectangle方法的具体用法?C# GraphicsPath.AddRoundedRectangle怎么用?C# GraphicsPath.AddRoundedRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath.AddRoundedRectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
/// <summary>
/// The graphics device and clip rectangle are in the parent coordinates.
/// </summary>
/// <param name="g"></param>
/// <param name="clipRectangle"></param>
/// <param name="symbol">The symbol to use for drawing.</param>
public void Draw(Graphics g, Rectangle clipRectangle, ISymbol symbol)
{
Color topLeft;
Color bottomRight;
if (_isSelected)
{
topLeft = _selectionColor.Darker(.3F);
bottomRight = _selectionColor.Lighter(.3F);
}
else
{
topLeft = _backColor.Lighter(.3F);
bottomRight = _backColor.Darker(.3F);
}
LinearGradientBrush b = new LinearGradientBrush(_bounds, topLeft, bottomRight, LinearGradientMode.ForwardDiagonal);
GraphicsPath gp = new GraphicsPath();
gp.AddRoundedRectangle(Bounds, _roundingRadius);
g.FillPath(b, gp);
gp.Dispose();
b.Dispose();
Matrix old = g.Transform;
Matrix shift = g.Transform;
shift.Translate(_bounds.Left + _bounds.Width / 2, _bounds.Top + _bounds.Height / 2);
g.Transform = shift;
if (symbol != null)
{
OnDrawSymbol(g, symbol);
}
g.Transform = old;
}
示例2: DrawRoundedRectangle
public static void DrawRoundedRectangle(this Graphics g, Brush brush, Pen pen, Rectangle rect, float radius)
{
using (GraphicsPath gp = new GraphicsPath())
{
gp.AddRoundedRectangle(rect, radius);
if (brush != null) g.FillPath(brush, gp);
if (pen != null) g.DrawPath(pen, gp);
}
}
示例3: Draw
/// <summary>
/// Draws this slider on the specified graphics object
/// </summary>
/// <param name="g"></param>
public void Draw(Graphics g)
{
if (_visible == false) return;
if (_width == 0) return;
Rectangle bounds = GetBounds();
GraphicsPath gp = new GraphicsPath();
gp.AddRoundedRectangle(bounds, _roundingRadius);
LinearGradientBrush lgb = new LinearGradientBrush(bounds, Color.Lighter(.3F), Color.Darker(.3F), LinearGradientMode.ForwardDiagonal);
g.FillPath(lgb, gp);
lgb.Dispose();
gp.Dispose();
}
示例4: Get3DShinePath
private const double ROUNDED_RECT_RAD_PERCENT = .05d; //5 percent
#endregion Fields
#region Methods
public static GraphicsPath Get3DShinePath(Rectangle container, ControlShape shape)
{
GraphicsPath path = new GraphicsPath();
Rectangle pathRect = container;
pathRect.Width -= 1;
pathRect.Height -= 1;
RectangleF halfRect = new RectangleF(pathRect.X, pathRect.Y,
pathRect.Width, pathRect.Height / 2f);
if (pathRect.Height > 0 && pathRect.Width > 0)
{
switch (shape)
{
case ControlShape.Rect:
path.AddRectangle(halfRect);
break;
case ControlShape.RoundedRect:
//radius is 10% of smallest side
int rad = (int)(Math.Min(halfRect.Height, halfRect.Width) * ROUNDED_RECT_RAD_PERCENT);
path.AddRoundedRectangle(halfRect, rad);
break;
case ControlShape.Circular:
path.AddArc(pathRect, 180, 142);
PointF[] pts = new PointF[]
{
path.GetLastPoint(),
new PointF(container.Width * .70f, container.Height * .33f),
new PointF(container.Width * .25f, container.Height * .5f),
path.PathPoints[0]
};
path.AddCurve(pts);
path.CloseFigure();
break;
}
}
return path;
}
示例5: Draw
/// <summary>
/// Draws this slider on the specified graphics object
/// </summary>
/// <param name="g"></param>
public void Draw(Graphics g)
{
if (_visible == false) return;
if (_width == 0) return;
Rectangle bounds = GetBounds();
GraphicsPath gp = new GraphicsPath();
gp.AddRoundedRectangle(bounds, _roundingRadius);
LinearGradientBrush lgb = new LinearGradientBrush(bounds, Color.Lighter(.3F), Color.Darker(.3F), LinearGradientMode.ForwardDiagonal);
g.FillPath(lgb, gp);
Pen l = new Pen(Color.Darker(.2f), 2);
Pen r = new Pen(Color.Lighter(.2f), 2);
if (_left)
{
g.DrawLine(l, bounds.Right - 1, bounds.Top, bounds.Right - 1, bounds.Height);
}
else
{
g.DrawLine(r, bounds.Left + 1, bounds.Top, bounds.Left + 1, bounds.Right);
}
l.Dispose();
r.Dispose();
lgb.Dispose();
gp.Dispose();
}
示例6: DrawWatermarkText
private Image DrawWatermarkText(Image img, string drawText)
{
if (!string.IsNullOrEmpty(drawText) && Config.WatermarkFont.Size > 0)
{
Font font = null;
Brush backgroundBrush = null;
try
{
int offset = Config.WatermarkOffset;
font = Config.WatermarkFont;
Size textSize = TextRenderer.MeasureText(drawText, font);
Size labelSize = new Size(textSize.Width + 10, textSize.Height + 10);
Point labelPosition = FindPosition(Config.WatermarkPositionMode, offset, img.Size, new Size(textSize.Width + 10, textSize.Height + 10), 1);
if (Config.WatermarkAutoHide && ((img.Width < labelSize.Width + offset) || (img.Height < labelSize.Height + offset)))
{
return img;
}
Rectangle labelRectangle = new Rectangle(Point.Empty, labelSize);
Color fontColor = Config.WatermarkFontArgb;
using (Bitmap bmp = new Bitmap(labelRectangle.Width + 1, labelRectangle.Height + 1))
using (Graphics g = Graphics.FromImage(bmp))
{
g.SmoothingMode = SmoothingMode.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
if (Config.WatermarkUseCustomGradient)
{
backgroundBrush = GradientMaker.CreateGradientBrush(labelRectangle.Size, Config.WatermarkGradient);
}
else
{
backgroundBrush = new LinearGradientBrush(labelRectangle, Config.WatermarkGradient1Argb, Config.WatermarkGradient2Argb, Config.WatermarkGradientType);
}
using (GraphicsPath gPath = new GraphicsPath())
using (Pen borderPen = new Pen(Config.WatermarkBorderArgb))
{
gPath.AddRoundedRectangle(labelRectangle, Config.WatermarkCornerRadius);
g.FillPath(backgroundBrush, gPath);
g.DrawPath(borderPen, gPath);
}
using (Brush textBrush = new SolidBrush(fontColor))
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
{
g.DrawString(drawText, font, textBrush, bmp.Width / 2f, bmp.Height / 2f, sf);
}
using (Graphics gImg = Graphics.FromImage(img))
{
gImg.SmoothingMode = SmoothingMode.HighQuality;
gImg.DrawImage(bmp, labelPosition.X, labelPosition.Y, bmp.Width, bmp.Height);
if (Config.WatermarkAddReflection)
{
using (Bitmap bmp2 = ImageHelpers.AddReflection(bmp, 50, 150, 10))
{
gImg.DrawImage(bmp2, new Rectangle(labelPosition.X, labelPosition.Y + bmp.Height - 1, bmp2.Width, bmp2.Height));
}
}
}
}
}
catch (Exception ex)
{
DebugHelper.WriteException(ex, "Error while drawing watermark");
}
finally
{
if (font != null) font.Dispose();
if (backgroundBrush != null) backgroundBrush.Dispose();
}
}
return img;
}
示例7: Apply
public override Image Apply(Image img)
{
if (string.IsNullOrEmpty(Text))
{
return img;
}
using (Font textFont = TextFont)
{
if (textFont == null || textFont.Size < 1)
{
return img;
}
NameParser parser = new NameParser(NameParserType.Text) { Picture = img };
string parsedText = parser.Parse(Text);
Size textSize = Helpers.MeasureText(parsedText, textFont);
Size watermarkSize = new Size(textSize.Width + BackgroundPadding * 2, textSize.Height + BackgroundPadding * 2);
Point watermarkPosition = Helpers.GetPosition(Placement, Offset, img.Size, watermarkSize);
Rectangle watermarkRectangle = new Rectangle(watermarkPosition, watermarkSize);
if (AutoHide && !new Rectangle(0, 0, img.Width, img.Height).Contains(watermarkRectangle))
{
return img;
}
using (Graphics g = Graphics.FromImage(img))
{
g.SetHighQuality();
using (GraphicsPath gp = new GraphicsPath())
{
gp.AddRoundedRectangle(watermarkRectangle, CornerRadius);
if (DrawBackground)
{
Brush backgroundBrush = null;
try
{
if (UseGradient)
{
if (UseCustomGradient && Gradient != null && Gradient.IsValid)
{
backgroundBrush = new LinearGradientBrush(watermarkRectangle, Color.Transparent, Color.Transparent, Gradient.Type);
ColorBlend colorBlend = new ColorBlend();
IEnumerable<GradientStop> gradient = Gradient.Colors.OrderBy(x => x.Location);
colorBlend.Colors = gradient.Select(x => x.Color).ToArray();
colorBlend.Positions = gradient.Select(x => x.Location / 100).ToArray();
((LinearGradientBrush)backgroundBrush).InterpolationColors = colorBlend;
}
else
{
backgroundBrush = new LinearGradientBrush(watermarkRectangle, BackgroundColor, BackgroundColor2, GradientType);
}
}
else
{
backgroundBrush = new SolidBrush(BackgroundColor);
}
g.FillPath(backgroundBrush, gp);
}
finally
{
if (backgroundBrush != null) backgroundBrush.Dispose();
}
}
if (DrawBorder)
{
using (Pen borderPen = new Pen(BorderColor))
{
g.DrawPath(borderPen, gp);
}
}
}
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
{
float centerX = watermarkRectangle.Width / 2f;
float centerY = watermarkRectangle.Height / 2f;
if (DrawTextShadow)
{
using (Brush textShadowBrush = new SolidBrush(TextShadowColor))
{
g.DrawString(parsedText, textFont, textShadowBrush, watermarkRectangle.X + centerX + TextShadowOffset.X, watermarkRectangle.Y + centerY + TextShadowOffset.Y, sf);
}
}
using (Brush textBrush = new SolidBrush(TextColor))
{
g.DrawString(parsedText, textFont, textBrush, watermarkRectangle.X + centerX, watermarkRectangle.Y + centerY, sf);
}
}
}
}
//.........这里部分代码省略.........
示例8: OnShapePathRequested
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
{
gp.AddRoundedRectangle(rect, CornerRadius);
}
示例9: OnDraw
/// <summary>
/// Controls the actual drawing for this gradient slider control.
/// </summary>
/// <param name="g"></param>
/// <param name="clipRectangle"></param>
protected virtual void OnDraw(Graphics g, Rectangle clipRectangle)
{
GraphicsPath gp = new GraphicsPath();
Rectangle innerRect = new Rectangle(_leftHandle.Width, 3, Width - 1 - _rightHandle.Width - _leftHandle.Width,
Height - 1 - 6);
gp.AddRoundedRectangle(innerRect, 2);
if (Width == 0 || Height == 0) return;
// Create a rounded gradient effect as the backdrop that other colors will be drawn to
LinearGradientBrush silver = new LinearGradientBrush(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.6F), LinearGradientMode.Vertical);
g.FillPath(silver, gp);
silver.Dispose();
LinearGradientBrush lgb = new LinearGradientBrush(innerRect, MinimumColor, MaximumColor, LinearGradientMode.Horizontal);
g.FillPath(lgb, gp);
lgb.Dispose();
g.DrawPath(Pens.Gray, gp);
gp.Dispose();
if (Enabled)
{
_leftHandle.Draw(g);
_rightHandle.Draw(g);
}
}
示例10: DrawSelectionHighlight
private void DrawSelectionHighlight(Graphics g, Rectangle clip, Rectangle gb)
{
if (_selectedRange == null) return;
int index = _colorRanges.IndexOf(_selectedRange);
if (index < 0) return;
float left = gb.Left;
if (_selectedRange.Range.Maximum < _minimum) return;
if (_selectedRange.Range.Minimum > _maximum) return;
if (_selectedRange.Range.Minimum != null)
{
float rangeLeft = GetPosition(_selectedRange.Range.Minimum.Value);
if (rangeLeft > left) left = rangeLeft;
}
float right = gb.Right;
if (_selectedRange.Range.Maximum != null)
{
float rangeRight = GetPosition(_selectedRange.Range.Maximum.Value);
if (rangeRight < right) right = rangeRight;
}
Rectangle selectionRect = new Rectangle((int)left, gb.Top, (int)(right - left), gb.Height);
if (!clip.IntersectsWith(selectionRect)) return;
GraphicsPath gp = new GraphicsPath();
gp.AddRoundedRectangle(selectionRect, 2);
if (selectionRect.Width != 0 && selectionRect.Height != 0)
{
LinearGradientBrush lgb = new LinearGradientBrush(selectionRect, Color.FromArgb(241, 248, 253), Color.FromArgb(213, 239, 252), LinearGradientMode.ForwardDiagonal);
g.FillPath(lgb, gp);
lgb.Dispose();
}
gp.Dispose();
}
示例11: OnDraw
/// <summary>
/// Custom drawing code
/// </summary>
/// <param name="g"></param>
/// <param name="clipRectangle"></param>
protected virtual void OnDraw(Graphics g, Rectangle clipRectangle)
{
Brush b = new SolidBrush(_color);
Color pressedLight = _color.Lighter(.2F);
Color pressedDark = _color.Darker(.4F);
Color light = _color.Lighter(.3F);
Color dark = _color.Darker(.3F);
Rectangle bounds = new Rectangle(0, 0, Width - 1, Height - 1);
GraphicsPath gp = new GraphicsPath();
// Even when fully transparent, I would like to see a "glass like" reflective appearance
LinearGradientBrush crystalBrush;
Color cLight = Color.FromArgb(80, Color.LightCyan.Lighter(.3F));
Color cDark = Color.FromArgb(80, Color.DarkCyan).Darker(.3F);
if (_isDown == false)
{
crystalBrush = new LinearGradientBrush(new Point(0, 0), new Point(bounds.Width, bounds.Height), cLight, cDark);
}
else
{
crystalBrush = new LinearGradientBrush(new Point(0, 0), new Point(bounds.Width, bounds.Height), cDark, cLight);
}
LinearGradientBrush lgb;
if (_isDown == false)
{
lgb = new LinearGradientBrush(new Point(0, 0), new Point(bounds.Width, bounds.Height), light, dark);
}
else
{
lgb = new LinearGradientBrush(new Point(0, 0), new Point(bounds.Width, bounds.Height), pressedDark, pressedLight);
}
int rad = Math.Min(Math.Min(_roundingRadius, Width / 2), Height / 2);
gp.AddRoundedRectangle(bounds, rad);
g.FillPath(crystalBrush, gp);
g.FillPath(lgb, gp);
gp.Dispose();
if (Width < _bevelRadius * 2 || Height < _bevelRadius * 2)
{
}
else
{
Rectangle inner = new Rectangle(bounds.Left + _bevelRadius, bounds.Top + _bevelRadius, bounds.Width - _bevelRadius * 2, bounds.Height - _bevelRadius * 2);
gp = new GraphicsPath();
int rRad = _roundingRadius - _bevelRadius;
if (rRad < 0) rRad = 0;
gp.AddRoundedRectangle(inner, rRad);
Color cPlain = Color.FromArgb(20, Color.Cyan);
SolidBrush back = new SolidBrush(BackColor);
SolidBrush crystalFlat = new SolidBrush(cPlain);
g.FillPath(back, gp);
g.FillPath(crystalFlat, gp);
back.Dispose();
crystalFlat.Dispose();
g.FillPath(b, gp);
gp.Dispose();
}
b.Dispose();
}
示例12: AddShapePath
protected override void AddShapePath(GraphicsPath graphicsPath, Rectangle rect)
{
graphicsPath.AddRoundedRectangle(rect, Radius);
}
示例13: RoundedCorners
public static Image RoundedCorners(Image img, int cornerRadius)
{
Bitmap bmp = img.CreateEmptyBitmap();
using (Graphics g = Graphics.FromImage(bmp))
using (img)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (GraphicsPath gp = new GraphicsPath())
{
gp.AddRoundedRectangle(new RectangleF(0, 0, img.Width, img.Height), cornerRadius);
using (TextureBrush brush = new TextureBrush(img))
{
g.FillPath(brush, gp);
}
}
}
return bmp;
}
示例14: Draw
/// <summary>
/// Instructs this button to draw itself.
/// </summary>
/// <param name="g">The graphics surface to draw to.</param>
public void Draw(Graphics g)
{
if (_bounds.Width == 0 || _bounds.Height == 0) return;
Pen border = null;
// Pen innerBorder = Pens.White;
Brush fill = null;
if (!_selected && !_highlighted)
{
border = new Pen(Color.Gray);
fill = new LinearGradientBrush(Bounds, BackColor.Lighter(.2f), BackColor.Darker(.2f), 45);
}
if (!_selected && _highlighted)
{
border = new Pen(Color.FromArgb(216, 240, 250));
fill = new LinearGradientBrush(Bounds, Color.FromArgb(245, 250, 253), Color.FromArgb(232, 245, 253), LinearGradientMode.Vertical);
}
if (_selected && !_highlighted)
{
border = new Pen(Color.FromArgb(153, 222, 253));
fill = new LinearGradientBrush(Bounds, Color.FromArgb(241, 248, 253), Color.FromArgb(213, 239, 252), LinearGradientMode.Vertical);
}
if (_selected && _highlighted)
{
border = new Pen(Color.FromArgb(182, 230, 251));
fill = new LinearGradientBrush(Bounds, Color.FromArgb(232, 246, 253), Color.FromArgb(196, 232, 250), LinearGradientMode.Vertical);
}
GraphicsPath gp = new GraphicsPath();
gp.AddRoundedRectangle(Bounds, 2);
if (fill != null) g.FillPath(fill, gp);
if (border != null) g.DrawPath(border, gp);
gp.Dispose();
if (fill != null) fill.Dispose();
}
示例15: AddShapePath
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
{
gp.AddRoundedRectangle(rect, Radius);
}