GraphicsPath.GetBounds メソッド ()
この GraphicsPath オブジェクトに外接する四角形を返します。
Overloads Public Function GetBounds() As RectangleF
[C#]
public RectangleF GetBounds();
[C++]
public: RectangleF GetBounds();
[JScript]
public function GetBounds() : RectangleF;
戻り値
GraphicsPath オブジェクトに外接する四角形を表す RectangleF 構造体。
解説
返された外接する四角形のサイズは、端点キャップの種類、ペンの幅、およびペンのマイタ制限値によって影響を受けるため、境界によって指定されたパスに緩やかに一致します。近似式は、外接する初期の四角形をペン幅で膨らませ、この結果にマイタ制限値を掛け合わせ、端点キャップのための追加の余白を加算します。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 OnPaint イベントのオブジェクトである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- グラフィックス パスを作成します。
- そのパスに楕円 (円) を追加し、画面に描画します。
- GetBounds() を呼び出すことで円に外接する四角形を取得し、その四角形を画面に描画します。
- 2 番目のグラフィックス パスを作成します。
- 円を追加し、パスを幅 10 に拡張します。
- 画面にパスを描画します。
- 2 番目の円に外接する四角形を取得します。
- 画面に外接する四角形を描画します。
- 四角形のサイズをダイアログ ボックスに表示します。
[Visual Basic, C#] 右側に外接する四角形の方が (直線の幅が広いことを考慮して) 大きくなります。
Public Sub GetBoundsExample(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
[C#]
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());
}
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
GraphicsPath クラス | GraphicsPath メンバ | System.Drawing.Drawing2D 名前空間 | GraphicsPath.GetBounds オーバーロードの一覧