閱讀英文

共用方式為


GraphicsUnit 列舉

定義

指定所指定資料的測量單位。

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

欄位

名稱 Description
Display 1

指定顯示裝置的測量單位。 一般來說,視訊顯示會使用像素,而印表機會使用 1/100 英吋。

Document 5

指定文件單位 (1/300 英吋) 做為測量單位。

Inch 4

指定英吋做為測量單位。

Millimeter 6

指定公釐做為測量單位。

Pixel 2

指定裝置像素做為測量單位。

Point 3

指定印表機的點 (1/72 英吋) 做為測量單位。

World 0

指定全局座標系統的單位做為測量單位。

範例

下列程式代碼範例示範如何使用 列舉從句柄載入點陣圖 IconGraphicsUnit 以及使用 Round 方法來繪製位圖的矩形界限。

此範例的設計目的是要與 Windows Forms 搭配使用。 Create 表單,其中包含名為 Button2 的按鈕。 將程式代碼貼到表單中,並將這個方法與按鈕的事件 Click 產生關聯。

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9