本文整理汇总了C#中RectangleF.ToDrawingRectF方法的典型用法代码示例。如果您正苦于以下问题:C# RectangleF.ToDrawingRectF方法的具体用法?C# RectangleF.ToDrawingRectF怎么用?C# RectangleF.ToDrawingRectF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RectangleF
的用法示例。
在下文中一共展示了RectangleF.ToDrawingRectF方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRoundedRectWithTitleRegionPath
/// <summary>
/// Creates a rectangular <see cref="GraphicsPath"/> with rounded edges, optionally with an open title
/// region specified by the parameters <paramref name="titleInset"/> and <paramref name="titleWidth"/>.
/// </summary>
/// <param name="baseRect">The rect which surrounds the created path.</param>
/// <param name="radiusX">The X radius of the rounded edges.</param>
/// <param name="radiusY">The Y radius of the rounded edges.</param>
/// <param name="withTitleRegion">If set to <c>true</c>, a title region will be left out.</param>
/// <param name="titleInset">Inset of the title region behind the corner. This parameter will only be used if
/// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param>
/// <param name="titleWidth">Width of the title region to leave out. This parameter will only be used if
/// <paramref name="withTitleRegion"/> is set to <c>true</c>.</param>
public static GraphicsPath CreateRoundedRectWithTitleRegionPath(RectangleF baseRect, float radiusX, float radiusY,
bool withTitleRegion, float titleInset, float titleWidth)
{
GraphicsPath result = new GraphicsPath();
if (radiusX <= 0.0f && radiusY <= 0.0f || baseRect.Width == 0 || baseRect.Height == 0)
{
// if corner radius is less than or equal to zero, return the original rectangle
if (withTitleRegion)
{ // If we should leave out a title region, we need to do it manually, because we need to start next to the
// title.
titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * titleInset);
// Right from the title to the upper right edge
result.AddLine(baseRect.Left + 2* titleInset + titleWidth, baseRect.Top,
baseRect.Right, baseRect.Top);
// Upper right edge to lower right edge
result.AddLine(baseRect.Right, baseRect.Top,
baseRect.Right, baseRect.Bottom);
// Lower right edge to lower left edge
result.AddLine(baseRect.Right, baseRect.Bottom,
baseRect.Left, baseRect.Bottom);
// Lower left edge to upper left edge
result.AddLine(baseRect.Left, baseRect.Bottom,
baseRect.Left, baseRect.Top);
// Upper left edge to the left side of the title
result.AddLine(baseRect.Left, baseRect.Top, baseRect.Left + titleInset, baseRect.Top);
}
else
result.AddRectangle(baseRect.ToDrawingRectF());
}
else
{
if (radiusX >= baseRect.Width / 2f)
radiusX = baseRect.Width/2f;
if (radiusY >= baseRect.Height / 2f)
radiusY = baseRect.Height/2f;
// create the arc for the rectangle sides and declare a graphics path object for the drawing
SizeF sizeF = new SizeF(radiusX * 2f, radiusY * 2f);
RectangleF arc = SharpDXExtensions.CreateRectangleF(baseRect.Location, sizeF);
if (withTitleRegion)
{
titleWidth = Math.Min(titleWidth, baseRect.Width - 2 * (radiusX + titleInset));
// Right of the title to the upper right edge
result.AddLine(baseRect.Left + radiusX + titleInset + titleWidth, baseRect.Top,
baseRect.Right - radiusX, baseRect.Top);
}
// Top right arc
arc.X = baseRect.Right - radiusX * 2f;
result.AddArc(arc.ToDrawingRectF(), 270, 90);
// Bottom right arc
arc.Y = baseRect.Bottom - radiusY * 2f;
result.AddArc(arc.ToDrawingRectF(), 0, 90);
// Bottom left arc
arc.X = baseRect.Left;
result.AddArc(arc.ToDrawingRectF(), 90, 90);
// Top left arc
arc.Y = baseRect.Top;
result.AddArc(arc.ToDrawingRectF(), 180, 90);
if (withTitleRegion)
// Upper left edge to the left side of the title
result.AddLine(baseRect.Left + radiusX, baseRect.Top, baseRect.Left + radiusX + titleInset, baseRect.Top);
else
result.CloseFigure();
}
result.Flatten();
return result;
}