Region.GetBounds(Graphics) メソッド

定義

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

public:
 System::Drawing::RectangleF GetBounds(System::Drawing::Graphics ^ g);
public System.Drawing.RectangleF GetBounds (System.Drawing.Graphics g);
member this.GetBounds : System.Drawing.Graphics -> System.Drawing.RectangleF
Public Function GetBounds (g As Graphics) As RectangleF

パラメーター

g
Graphics

この Graphics が描画される Region

戻り値

指定の描画サーフェイスのこの RectangleF に外接する四角形を表す Region 構造体。

例外

gnullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • GraphicsPath 作成し、楕円を追加します。

  • パスを青で塗りつぶし、画面に描画します。

  • を使用するリージョンを作成します GraphicsPath

  • 2 番目の四角形と組み合わせたときに、領域の存在しない領域を取得します。

  • 領域の外接する四角形を取得し、赤で画面に描画します。

public:
   void GetBoundsExample( PaintEventArgs^ e )
   {
      // Create a GraphicsPath and add an ellipse to it.
      GraphicsPath^ myPath = gcnew GraphicsPath;
      Rectangle ellipseRect = Rectangle(20,20,100,100);
      myPath->AddEllipse( ellipseRect );

      // Fill the path with blue and draw it to the screen.
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
      e->Graphics->FillPath( myBrush, myPath );

      // Create a region using the GraphicsPath.
      System::Drawing::Region^ myRegion = gcnew System::Drawing::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 ) );
   }
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));
}
Public Sub GetBoundsExample(ByVal 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

注釈

グラフィックス コンテキストの現在の変換は、描画サーフェス上の領域内部を計算するために使用されます。 外接する四角形は、現在の変換に応じて、常に可能な限り最小の外接する四角形であるとは限りません。

適用対象