次の方法で共有


Region.GetBounds メソッド

Graphics オブジェクトの描画面のこの Region オブジェクトに外接する四角形を表す RectangleF 構造体を取得します。

Public Function GetBounds( _
   ByVal g As Graphics _) As RectangleF
[C#]
public RectangleF GetBounds(Graphicsg);
[C++]
public: RectangleF GetBounds(Graphics* g);
[JScript]
public function GetBounds(
   g : Graphics) : RectangleF;

パラメータ

  • g
    この Region オブジェクトの描画先となる Graphics オブジェクト。

戻り値

指定の描画面のこの Region オブジェクトに外接する四角形を表す RectangleF 構造体。

解説

グラフィックス コンテキストの現在の変換は、描画面の領域内部を計算するために使用されます。現在の変換によっては、外接する四角形が最小のものでない場合があります。

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • GraphicsPath を作成し、そのパスに楕円を追加します。
  • 青でパスを塗りつぶし、画面に描画します。
  • GraphicsPath を使用して領域を作成します。
  • 2 つ目の四角形と組み合わせたときの領域の非除外部分を取得します。
  • 領域に外接する四角形を取得し、赤で画面に描画します。
 
Public Sub GetBoundsExample(e As PaintEventArgs)
' Create a GraphicsPath and add an ellipse to it.
Dim myPath As New GraphicsPath()
Dim ellipseRect As New Rectangle(20, 20, 100, 100)
myPath.AddEllipse(ellipseRect)
' Fill the path with blue and draw it to the screen.
Dim myBrush As New SolidBrush(Color.Blue)
e.Graphics.FillPath(myBrush, myPath)
' Create a region using the GraphicsPath.
Dim myRegion As New [Region](myPath)
' Get the bounding rectangle for myRegion and draw it to the
' screen in Red.
Dim boundsRect As RectangleF = myRegion.GetBounds(e.Graphics)
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect))
End Sub
        
[C#] 
public void GetBoundsExample(PaintEventArgs e)
{
// Create a GraphicsPath and add an ellipse to it.
GraphicsPath myPath = new GraphicsPath();
Rectangle ellipseRect = new Rectangle(20, 20, 100, 100);
myPath.AddEllipse(ellipseRect);
// Fill the path with blue and draw it to the screen.
SolidBrush myBrush = new SolidBrush(Color.Blue);
e.Graphics.FillPath(myBrush, myPath);
// Create a region using the GraphicsPath.
Region myRegion = new Region(myPath);
// Get the bounding rectangle for myRegion and draw it to the
// screen in Red.
RectangleF boundsRect = myRegion.GetBounds(e.Graphics);
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect));
}
        

[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 ファミリ, .NET Compact Framework - Windows CE .NET

参照

Region クラス | Region メンバ | System.Drawing 名前空間