Graphics.GetHdc メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As Graphics Dim returnValue As IntPtr returnValue = instance.GetHdc
この Graphics に関連付けられているデバイス コンテキストを識別するハンドル。

デバイス コンテキストは、グラフィカル オブジェクトのセット、それらに関連付けられた属性、および出力に影響を与えるグラフィカル モードを定義する GDI ベースの Windows 構造体です。このメソッドは、フォントの例外でそのデバイス コンテキストを返します。フォントが選択されていないため、GetHdc メソッドから返されたハンドルを使用した FromHdc メソッドの呼び出しは失敗します。
GetHdc メソッドと ReleaseHdc メソッドの呼び出しは、ペアで表示する必要があります。GetHdc メソッドと ReleaseHdc メソッドのペアのスコープ内では、通常は GDI 関数だけを呼び出します。hdc パラメータを生成した Graphics の GDI+ メソッドをこのスコープ内で呼び出すと、その呼び出しは失敗し、ObjectBusy エラーが返されます。さらに GDI+ は、以降の操作で hdc パラメータの Graphics に加えられる状態の変更をすべて無視します。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。この例では、Windows GDI 関数を呼び出して、GDI+Graphics メソッドと同じタスクを実行します。このコードは次のアクションを実行します。
Public Class GDI <System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _ Friend Shared Function Rectangle(ByVal hdc As IntPtr, _ ByVal ulCornerX As Integer, ByVal ulCornerY As Integer, ByVal lrCornerX As Integer, _ ByVal lrCornerY As Integer) As Boolean End Function End Class <System.Security.Permissions.SecurityPermission( _ System.Security.Permissions.SecurityAction.LinkDemand, Flags := _ System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _ Public Sub GetHdcForGDI1(ByVal e As PaintEventArgs) ' Create pen. Dim redPen As New Pen(Color.Red, 1) ' Draw rectangle with GDI+. e.Graphics.DrawRectangle(redPen, 10, 10, 100, 50) ' Get handle to device context. Dim hdc As IntPtr = e.Graphics.GetHdc() ' Draw rectangle with GDI using default pen. GDI.Rectangle(hdc, 10, 70, 110, 120) ' Release handle to device context. e.Graphics.ReleaseHdc(hdc) End Sub
public class GDI { [System.Runtime.InteropServices.DllImport("gdi32.dll")] internal static extern bool Rectangle( IntPtr hdc, int ulCornerX, int ulCornerY, int lrCornerX, int lrCornerY); } [System.Security.Permissions.SecurityPermission( System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] public void GetHdcForGDI1(PaintEventArgs e) { // Create pen. Pen redPen = new Pen(Color.Red, 1); // Draw rectangle with GDI+. e.Graphics.DrawRectangle(redPen, 10, 10, 100, 50); // Get handle to device context. IntPtr hdc = e.Graphics.GetHdc(); // Draw rectangle with GDI using default pen. GDI.Rectangle(hdc, 10, 70, 110, 120); // Release handle to device context. e.Graphics.ReleaseHdc(hdc); }

- SecurityPermission (アンマネージ コードへのアクセスに必要なアクセス許可)。UnmanagedCode (関連する列挙体)

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGraphics.GetHdc メソッドを検索する場合は、下記のリンクをクリックしてください。

- Graphics.GetHdc メソッドのページへのリンク