GraphicsPath.GetBounds 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个矩形,该矩形绑定此 GraphicsPath。
重载
GetBounds() |
返回一个矩形,该矩形绑定此 GraphicsPath。 |
GetBounds(Matrix) |
返回一个矩形,当此路径由指定的 Matrix转换时绑定此 GraphicsPath。 |
GetBounds(Matrix, Pen) |
返回一个矩形,当当前路径由指定的 Matrix 转换并使用指定的 Pen绘制时,该矩形将此 GraphicsPath 绑定。 |
GetBounds()
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- 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
返回
一个表示此 GraphicsPath的矩形的 RectangleF。
示例
下面的代码示例旨在与 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
注解
返回的边界矩形的大小受结束帽、笔宽和笔 miter 限制的类型的影响,因此会生成一个“松散的拟合”到边界路径。 近似公式是:初始边界矩形由笔宽膨胀,此结果乘以 miter 限制,外加一些额外的边距以允许结束上限。
适用于
GetBounds(Matrix)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
返回一个矩形,当此路径由指定的 Matrix转换时绑定此 GraphicsPath。
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
参数
返回
一个表示此 GraphicsPath的矩形的 RectangleF。
示例
有关示例,请参阅 GetBounds()。
注解
返回的边界矩形的大小受结束帽、笔宽和笔 miter 限制的类型的影响,因此会生成一个“松散的拟合”到边界路径。 近似公式是:初始边界矩形由笔宽膨胀,此结果乘以 miter 限制,外加一些额外的边距以允许结束上限。
适用于
GetBounds(Matrix, Pen)
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
- Source:
- GraphicsPath.cs
返回一个矩形,当当前路径由指定的 Matrix 转换并使用指定的 Pen绘制时,该矩形将此 GraphicsPath 绑定。
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
绘制 GraphicsPathPen。
返回
一个表示此 GraphicsPath的矩形的 RectangleF。
示例
有关示例,请参阅 GetBounds()。
注解
返回的边界矩形的大小受结束帽、笔宽和笔 miter 限制的类型的影响,因此会生成一个“松散的拟合”到边界路径。 近似公式是:初始边界矩形由笔宽膨胀,此结果乘以 miter 限制,外加一些额外的边距以允许结束上限。