Graphics.FromHdc 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從指定的句柄建立一個新的 Graphics 裝置上下文。
多載
| 名稱 | Description |
|---|---|
| FromHdc(IntPtr, IntPtr) |
從指定的句柄建立一個新的句柄到裝置上下文,並建立一個裝置 Graphics 的句柄。 |
| FromHdc(IntPtr) |
從指定的句柄建立一個新的 Graphics 裝置上下文。 |
FromHdc(IntPtr, IntPtr)
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
從指定的句柄建立一個新的句柄到裝置上下文,並建立一個裝置 Graphics 的句柄。
public:
static System::Drawing::Graphics ^ FromHdc(IntPtr hdc, IntPtr hdevice);
public static System.Drawing.Graphics FromHdc(IntPtr hdc, IntPtr hdevice);
static member FromHdc : nativeint * nativeint -> System.Drawing.Graphics
Public Shared Function FromHdc (hdc As IntPtr, hdevice As IntPtr) As Graphics
參數
- hdc
-
IntPtr
nativeint
裝置內容的句柄。
- hdevice
-
IntPtr
nativeint
處理裝置。
傳回
此方法會回傳指定的裝置上下文與裝置的新資料 Graphics 。
備註
你應該總是呼叫該 Dispose 方法來釋放 Graphics 該 FromHdc 方法所產生的相關資源。
即使顯示裝置有相關的 ICM 色彩設定檔,GDI+ 預設也不會使用該設定檔。 要啟用 ICMGraphics,請在將 HDC(及 ICM_ON)傳給Graphics函數後,從 HDC 構造 。SetICMMode 接著,任何由 S Graphics 繪製的圖紙都會根據顯示裝置所對應的 ICM 配置檔進行調整。 啟用 ICM 會導致效能變慢。
你呼叫 FromHdc 時裝置上下文的狀態(映射模式、邏輯單元等)會影響由 Graphics.
裝置 handle 通常用於查詢特定印表機的功能。
適用於
FromHdc(IntPtr)
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
從指定的句柄建立一個新的 Graphics 裝置上下文。
public:
static System::Drawing::Graphics ^ FromHdc(IntPtr hdc);
public static System.Drawing.Graphics FromHdc(IntPtr hdc);
static member FromHdc : nativeint -> System.Drawing.Graphics
Public Shared Function FromHdc (hdc As IntPtr) As Graphics
參數
- hdc
-
IntPtr
nativeint
裝置內容的句柄。
傳回
此方法會回傳指定的裝置上下文的新資料 Graphics 。
範例
以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 程式代碼會執行下列動作:
建立一個內部指標型態變數
hdc,並將其設定為表單圖形物件的裝置上下文的代柄。使用
hdc。在螢幕上畫出一個帶有新圖形物件的矩形。
以
hdc. 釋出新的圖形物件。
public:
void FromHdcHdc( PaintEventArgs^ e )
{
// Get handle to device context.
IntPtr hdc = e->Graphics->GetHdc();
// Create new graphics object using handle to device context.
Graphics^ newGraphics = Graphics::FromHdc( hdc );
// Draw rectangle to screen.
newGraphics->DrawRectangle( gcnew Pen( Color::Red,3.0f ), 0, 0, 200, 100 );
// Release handle to device context and dispose of the // Graphics object
e->Graphics->ReleaseHdc( hdc );
delete newGraphics;
}
private void FromHdcHdc(PaintEventArgs e)
{
// Get handle to device context.
IntPtr hdc = e.Graphics.GetHdc();
// Create new graphics object using handle to device context.
Graphics newGraphics = Graphics.FromHdc(hdc);
// Draw rectangle to screen.
newGraphics.DrawRectangle(new Pen(Color.Red, 3), 0, 0, 200, 100);
// Release handle to device context and dispose of the // Graphics object
e.Graphics.ReleaseHdc(hdc);
newGraphics.Dispose();
}
<System.Security.Permissions.SecurityPermission( _
System.Security.Permissions.SecurityAction.LinkDemand, Flags := _
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
Private Sub FromHdcHdc(ByVal e As PaintEventArgs)
' Get handle to device context.
Dim hdc As IntPtr = e.Graphics.GetHdc()
' Create new graphics object using handle to device context.
Dim newGraphics As Graphics = Graphics.FromHdc(hdc)
' Draw rectangle to screen.
newGraphics.DrawRectangle(New Pen(Color.Red, 3), 0, 0, 200, 100)
' Release handle to device context and dispose of the Graphics ' object
e.Graphics.ReleaseHdc(hdc)
newGraphics.Dispose()
End Sub
備註
你應該總是呼叫該 Dispose 方法來釋放 Graphics 該 FromHdc 方法所產生的相關資源。
即使顯示裝置有相關的 ICM 色彩設定檔,GDI+ 預設也不會使用該設定檔。 要啟用 ICMGraphics,請在將 HDC(及 ICM_ON)傳給Graphics函數後,從 HDC 構造 。SetICMMode 接著,任何由 S Graphics 繪製的圖紙都會根據顯示裝置所對應的 ICM 配置檔進行調整。 啟用 ICM 會導致效能變慢。
你呼叫 FromHdc 時裝置上下文的狀態(映射模式、邏輯單元等)會影響由 Graphics.