Image.GetBounds(GraphicsUnit) Image.GetBounds(GraphicsUnit) Image.GetBounds(GraphicsUnit) Image.GetBounds(GraphicsUnit) Method

定義

指定した単位でイメージの境界を取得します。Gets the bounds of the image in the specified unit.

public:
 System::Drawing::RectangleF GetBounds(System::Drawing::GraphicsUnit % pageUnit);
public System.Drawing.RectangleF GetBounds (ref System.Drawing.GraphicsUnit pageUnit);
member this.GetBounds :  -> System.Drawing.RectangleF
Public Function GetBounds (ByRef pageUnit As GraphicsUnit) As RectangleF

パラメーター

pageUnit
GraphicsUnit GraphicsUnit GraphicsUnit GraphicsUnit

外接する四角形の長さの単位を示す GraphicsUnit 値のいずれか。One of the GraphicsUnit values indicating the unit of measure for the bounding rectangle.

戻り値

指定した単位でイメージの境界を表す RectangleFThe RectangleF that represents the bounds of the image, in the specified unit.

次のコード例からビットマップを読み込む方法を示します、Iconを使用して、処理、GraphicsUnit列挙、および使用する方法、Roundビットマップの四角形の境界を描画するメソッド。The following code example demonstrates how to load a bitmap from an Icon handle, using the GraphicsUnit enumeration, and how to use the Round method to draw the rectangle bounds of a bitmap.

この例は、Windows フォームで使用する設計されています。This example is designed to be used with Windows Forms. という名前のボタンを含むフォームを作成するButton2します。Create a form that contains a button named Button2. フォームにコードを貼り付け、ボタンのこのメソッドを関連付けるClickイベント。Paste the code into the form and associate this method with the button's Click event.

void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   Bitmap^ bitmap1 = Bitmap::FromHicon( SystemIcons::Hand->Handle );
   Graphics^ formGraphics = this->CreateGraphics();
   GraphicsUnit units = GraphicsUnit::Point;
   RectangleF bmpRectangleF = bitmap1->GetBounds( units );
   Rectangle bmpRectangle = Rectangle::Round( bmpRectangleF );
   formGraphics->DrawRectangle( Pens::Blue, bmpRectangle );
   delete formGraphics;
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{

    Bitmap bitmap1 = Bitmap.FromHicon(SystemIcons.Hand.Handle);
    Graphics formGraphics = this.CreateGraphics();
    GraphicsUnit units = GraphicsUnit.Point;

    RectangleF bmpRectangleF = bitmap1.GetBounds(ref units);
    Rectangle bmpRectangle = Rectangle.Round(bmpRectangleF);
    formGraphics.DrawRectangle(Pens.Blue, bmpRectangle);
    formGraphics.Dispose();
}
Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click

    Dim bitmap1 As Bitmap = Bitmap.FromHicon(SystemIcons.Hand.Handle)
    Dim formGraphics As Graphics = Me.CreateGraphics()
    Dim units As GraphicsUnit = GraphicsUnit.Point
    Dim bmpRectangleF As RectangleF = bitmap1.GetBounds(units)
    Dim bmpRectangle As Rectangle = Rectangle.Round(bmpRectangleF)
    formGraphics.DrawRectangle(Pens.Blue, bmpRectangle)
    formGraphics.Dispose()
End Sub

適用対象