語言

GraphicsPath.GetBounds 方法

定義

回傳一個將此 GraphicsPath界定的矩形。

多載

名稱 Description
GetBounds()

回傳一個將此 GraphicsPath界定的矩形。

GetBounds(Matrix)

當該路徑被指定的 GraphicsPath變換時,回傳一個矩形,該矩形界定了此路徑Matrix。

GetBounds(Matrix, Pen)

當當前路徑被指定GraphicsPath轉換並繪Matrix製時,回傳一個矩形,該矩形界定於此Pen範圍。

GetBounds()

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

傳回

A 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

備註

返回邊界矩形的大小受端帽類型、筆寬度及筆尖斜接限制影響,因此產生對有界路徑的「鬆散擬合」。 大致公式是:初始邊界矩形被筆寬膨脹,然後乘以斜切極限,加上一些額外的邊距以允許端帽。

適用於

GetBounds(Matrix)

來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
GraphicsPath.cs
來源:
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 指定在計算界線矩形前,對此路徑施加一個變換。 這條路不會被永久改變;此轉換僅用於計算包圍矩形的過程中。

傳回

A RectangleF 代表一個界定此 GraphicsPath的矩形。

範例

如需範例,請參閱 GetBounds()。

備註

返回邊界矩形的大小受端帽類型、筆寬度及筆尖斜接限制影響,因此產生對有界路徑的「鬆散擬合」。 大致公式是:初始邊界矩形被筆寬膨脹,然後乘以斜切極限,加上一些額外的邊距以允許端帽。

適用於

GetBounds(Matrix, Pen)

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

用來Pen繪製 。GraphicsPath

傳回

A RectangleF 代表一個界定此 GraphicsPath的矩形。

範例

如需範例,請參閱 GetBounds()。

備註

返回邊界矩形的大小受端帽類型、筆寬度及筆尖斜接限制影響,因此產生對有界路徑的「鬆散擬合」。 大致公式是:初始邊界矩形被筆寬膨脹,然後乘以斜切極限,加上一些額外的邊距以允許端帽。

適用於