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


GetHdc と ReleaseHdc は、Windows デバイスのハンドルを取得および解放するためのメソッドです。Windows ハンドルを使い終えたら、GetHdc に続けて ReleaseHdc を必ず呼び出してください。

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

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


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


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

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。この例では、Windows GDI 関数を呼び出して、GDI+Graphics メソッドと同じタスクを実行します。このコードは次のアクションを実行します。
-
Windows DLL ファイル gdi32.dll の相互運用性 DllImportAttribute 属性を定義します。この DLL は必要な GDI 関数を格納しており、その DLL の Rectangle 関数を外部関数として定義します。
<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _ Private Shared Function Rectangle2(ByVal hdc As IntPtr, _ ByVal ulCornerX As Integer, ByVal ulCornerY As Integer, ByVal lrCornerX As Integer, _ ByVal lrCornerY As Integer) As Boolean End Function <System.Security.Permissions.SecurityPermission( _ System.Security.Permissions.SecurityAction.LinkDemand, Flags := _ System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _ Public Sub GetHdcForGDI2(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. Rectangle2(hdc, 10, 70, 110, 120) ' Release handle to device context. e.Graphics.ReleaseHdc(hdc) End Sub
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")] private static extern bool Rectangle2( 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 GetHdcForGDI2(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. Rectangle2(hdc, 10, 70, 110, 120); // Release handle to device context. e.Graphics.ReleaseHdc(hdc); }

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

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


Graphics.ReleaseHdc メソッド

名前 | 説明 |
---|---|
Graphics.ReleaseHdc () | この Graphics の GetHdc メソッドを前回呼び出したときに取得したデバイス コンテキスト ハンドルを解放します。 |
Graphics.ReleaseHdc (IntPtr) | この Graphics の GetHdc メソッドを前回呼び出したときに取得したデバイス コンテキスト ハンドルを解放します。 .NET Compact Framework によってサポートされています。 |

- Graphics.ReleaseHdcのページへのリンク