GraphicsPath.GetBounds 方法

定義

傳回限定這個 GraphicsPath 之界限的矩形。

多載

GetBounds()

傳回限定這個 GraphicsPath 之界限的矩形。

GetBounds(Matrix)

當這個 GraphicsPath 路徑由指定的 Matrix 轉換時,會傳回限定這個路徑之界限的矩形。

GetBounds(Matrix, Pen)

當目前路徑由指定的 GraphicsPath 轉換,並使用指定的 Matrix 繪製時,會傳回限定這個 Pen 之界限的矩形。

GetBounds()

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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 Forms 使用,而且需要 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)

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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

參數

matrix
Matrix

Matrix,指定在計算週框前要套用至這個路徑的轉換。 這個路徑不是永久地轉換;該轉換只會用在計算週框期間。

傳回

RectangleF,表示限定這個 GraphicsPath 之界限的矩形。

範例

如需範例,請參閱 GetBounds()

備註

傳回的周框大小會受到結束上限、畫筆寬度和畫筆Miter限制的類型影響,因此會產生「鬆散大小」到周框路徑。 近似公式為:初始周框會以畫筆寬度擴大,而此結果會乘以miter限制,再加上一些額外的邊界以允許結束上限。

適用於

GetBounds(Matrix, Pen)

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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

參數

matrix
Matrix

Matrix,指定在計算週框前要套用至這個路徑的轉換。 這個路徑不是永久地轉換;該轉換只會用在計算週框期間。

pen
Pen

用來繪製 PenGraphicsPath

傳回

RectangleF,表示限定這個 GraphicsPath 之界限的矩形。

範例

如需範例,請參閱 GetBounds()

備註

傳回的周框大小會受到結束上限、畫筆寬度和畫筆Miter限制的類型影響,因此會產生「鬆散大小」到周框路徑。 近似公式為:初始周框會以畫筆寬度擴大,而此結果會乘以miter限制,再加上一些額外的邊界以允許結束上限。

適用於