GraphicsUnit 列舉

定義

指定所指定資料的測量單位。Specifies the unit of measure for the given data.

public enum class GraphicsUnit
public enum GraphicsUnit
type GraphicsUnit = 
Public Enum GraphicsUnit
繼承
GraphicsUnit

欄位

Display 1

指定顯示裝置的測量單位。Specifies the unit of measure of the display device. 一般來說,視訊顯示會使用像素,而印表機會使用 1/100 英吋。Typically pixels for video displays, and 1/100 inch for printers.

Document 5

指定文件單位 (1/300 英吋) 做為測量單位。Specifies the document unit (1/300 inch) as the unit of measure.

Inch 4

指定英吋做為測量單位。Specifies the inch as the unit of measure.

Millimeter 6

指定公釐做為測量單位。Specifies the millimeter as the unit of measure.

Pixel 2

指定裝置像素做為測量單位。Specifies a device pixel as the unit of measure.

Point 3

指定印表機的點 (1/72 英吋) 做為測量單位。Specifies a printer's point (1/72 inch) as the unit of measure.

World 0

指定全局座標系統的單位做為測量單位。Specifies the world coordinate system unit as the unit of measure.

範例

下列程式碼範例示範如何從Icon控制碼載入點陣圖、 GraphicsUnit使用列舉, Round以及使用方法繪製點陣圖的矩形界限。The following code example demonstrates how to load a bitmap from an Icon handle, using the GraphicsUnit enumeration, and the use of the Round method to draw the rectangle bounds of a bitmap.

這個範例是設計來與 Windows Forms 搭配使用。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

適用於