GraphicsPath.GetBounds 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回限定此 GraphicsPath 的矩形。
重载
GetBounds() |
返回限定此 GraphicsPath 的矩形。 |
GetBounds(Matrix) |
返回当由指定的 GraphicsPath 对该路径进行变换时,限定此 Matrix 的矩形。 |
GetBounds(Matrix, Pen) |
返回当由指定的 GraphicsPath 对当前路径进行变换并且用指定的 Matrix 绘制该路径时,限定此 Pen 的矩形。 |
GetBounds()
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
返回限定此 GraphicsPath 的矩形。
public:
System::Drawing::RectangleF GetBounds();
public System.Drawing.RectangleF GetBounds ();
member this.GetBounds : unit -> System.Drawing.RectangleF
Public Function GetBounds () As RectangleF
返回
一个 RectangleF,表示限定此 GraphicsPath 的矩形。
示例
下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse
事件OnPaint对象。 此代码执行以下操作:
创建图形路径。
向它添加一个椭圆 (圆) ,并将其绘制到屏幕上。
使用 调用 GetBounds 检索圆的边框,并将矩形绘制到屏幕。
创建第二个图形路径。
添加一个圆,并将路径宽度扩大为 10。
绘制屏幕的路径。
检索第二个圆的边框。
将边界矩形绘制到屏幕。
在对话框中显示矩形大小。
请注意,右侧的边框较大, (考虑线条) 的额外宽度。
public:
void GetBoundsExample( PaintEventArgs^ e )
{
// Create path number 1 and a Pen for drawing.
GraphicsPath^ myPath = gcnew GraphicsPath;
Pen^ pathPen = gcnew Pen( Color::Black,1.0f );
// Add an Ellipse to the path and Draw it (circle in start
// position).
myPath->AddEllipse( 20, 20, 100, 100 );
e->Graphics->DrawPath( pathPen, myPath );
// Get the path bounds for Path number 1 and draw them.
RectangleF boundRect = myPath->GetBounds();
e->Graphics->DrawRectangle( gcnew Pen( Color::Red,1.0f ), boundRect.X, boundRect.Y, boundRect.Height, boundRect.Width );
// Create a second graphics path and a wider Pen.
GraphicsPath^ myPath2 = gcnew GraphicsPath;
Pen^ pathPen2 = gcnew Pen( Color::Black,10.0f );
// Create a new ellipse with a width of 10.
myPath2->AddEllipse( 150, 20, 100, 100 );
myPath2->Widen( pathPen2 );
e->Graphics->FillPath( Brushes::Black, myPath2 );
// Get the second path bounds.
RectangleF boundRect2 = myPath2->GetBounds();
// Draw the bounding rectangle.
e->Graphics->DrawRectangle( gcnew Pen( Color::Red,1.0f ), boundRect2.X, boundRect2.Y, boundRect2.Height, boundRect2.Width );
// Display the rectangle size.
MessageBox::Show( boundRect2.ToString() );
}
public void GetBoundsExample(PaintEventArgs e)
{
// Create path number 1 and a Pen for drawing.
GraphicsPath myPath = new GraphicsPath();
Pen pathPen = new Pen(Color.Black, 1);
// Add an Ellipse to the path and Draw it (circle in start
// position).
myPath.AddEllipse(20, 20, 100, 100);
e.Graphics.DrawPath(pathPen, myPath);
// Get the path bounds for Path number 1 and draw them.
RectangleF boundRect = myPath.GetBounds();
e.Graphics.DrawRectangle(new Pen(Color.Red, 1),
boundRect.X,
boundRect.Y,
boundRect.Height,
boundRect.Width);
// Create a second graphics path and a wider Pen.
GraphicsPath myPath2 = new GraphicsPath();
Pen pathPen2 = new Pen(Color.Black, 10);
// Create a new ellipse with a width of 10.
myPath2.AddEllipse(150, 20, 100, 100);
myPath2.Widen(pathPen2);
e.Graphics.FillPath(Brushes.Black, myPath2);
// Get the second path bounds.
RectangleF boundRect2 = myPath2.GetBounds();
// Draw the bounding rectangle.
e.Graphics.DrawRectangle(new Pen(Color.Red, 1),
boundRect2.X,
boundRect2.Y,
boundRect2.Height,
boundRect2.Width);
// Display the rectangle size.
MessageBox.Show(boundRect2.ToString());
}
Public Sub GetBoundsExample(ByVal e As PaintEventArgs)
' Create path number 1 and a Pen for drawing.
Dim myPath As New GraphicsPath
Dim pathPen As New Pen(Color.Black, 1)
' Add an Ellipse to the path and Draw it (circle in start
' position).
myPath.AddEllipse(20, 20, 100, 100)
e.Graphics.DrawPath(pathPen, myPath)
' Get the path bounds for Path number 1 and draw them.
Dim boundRect As RectangleF = myPath.GetBounds()
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), boundRect.X, _
boundRect.Y, boundRect.Height, boundRect.Width)
' Create a second graphics path and a wider Pen.
Dim myPath2 As New GraphicsPath
Dim pathPen2 As New Pen(Color.Black, 10)
' Create a new ellipse with a width of 10.
myPath2.AddEllipse(150, 20, 100, 100)
myPath2.Widen(pathPen2)
e.Graphics.FillPath(Brushes.Black, myPath2)
' Get the second path bounds.
Dim boundRect2 As RectangleF = myPath2.GetBounds()
' Show the bounds in a message box.
e.Graphics.DrawString("Rectangle2 Bounds: " + _
boundRect2.ToString(), New Font("Arial", 8), Brushes.Black, _
20, 150)
' Draw the bounding rectangle.
e.Graphics.DrawRectangle(New Pen(Color.Red, 1), boundRect2.X, _
boundRect2.Y, boundRect2.Height, boundRect2.Width)
End Sub
注解
返回的边界矩形的大小受端盖类型、笔宽度和笔斜度限制的影响,因此会生成与边界路径的“松散拟合”。 近似公式为:初始边界矩形按笔宽度膨胀,此结果乘以斜面限制,以及允许端盖的一些额外边距。
适用于
GetBounds(Matrix)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
返回当由指定的 GraphicsPath 对该路径进行变换时,限定此 Matrix 的矩形。
public:
System::Drawing::RectangleF GetBounds(System::Drawing::Drawing2D::Matrix ^ matrix);
public System.Drawing.RectangleF GetBounds (System.Drawing.Drawing2D.Matrix matrix);
public System.Drawing.RectangleF GetBounds (System.Drawing.Drawing2D.Matrix? matrix);
member this.GetBounds : System.Drawing.Drawing2D.Matrix -> System.Drawing.RectangleF
Public Function GetBounds (matrix As Matrix) As RectangleF
参数
返回
一个 RectangleF,表示限定此 GraphicsPath 的矩形。
示例
有关示例,请参见 GetBounds()。
注解
返回的边界矩形的大小受端盖类型、笔宽度和笔斜度限制的影响,因此会生成与边界路径的“松散拟合”。 近似公式为:初始边界矩形按笔宽度膨胀,此结果乘以斜面限制,以及允许端盖的一些额外边距。
适用于
GetBounds(Matrix, Pen)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
返回当由指定的 GraphicsPath 对当前路径进行变换并且用指定的 Matrix 绘制该路径时,限定此 Pen 的矩形。
public:
System::Drawing::RectangleF GetBounds(System::Drawing::Drawing2D::Matrix ^ matrix, System::Drawing::Pen ^ pen);
public System.Drawing.RectangleF GetBounds (System.Drawing.Drawing2D.Matrix matrix, System.Drawing.Pen pen);
public System.Drawing.RectangleF GetBounds (System.Drawing.Drawing2D.Matrix? matrix, System.Drawing.Pen? pen);
member this.GetBounds : System.Drawing.Drawing2D.Matrix * System.Drawing.Pen -> System.Drawing.RectangleF
Public Function GetBounds (matrix As Matrix, pen As Pen) As RectangleF
参数
- pen
- Pen
Pen,用于绘制 GraphicsPath。
返回
一个 RectangleF,表示限定此 GraphicsPath 的矩形。
示例
有关示例,请参见 GetBounds()。
注解
返回的边界矩形的大小受端盖类型、笔宽度和笔斜度限制的影响,因此会生成与边界路径的“松散拟合”。 近似公式为:初始边界矩形按笔宽度膨胀,此结果乘以斜面限制,以及允许端盖的一些额外边距。
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈