Graphics.ReleaseHdc 메서드

정의

GraphicsGetHdc() 메서드에 대한 이전 호출에서 얻은 디바이스 컨텍스트 핸들을 해제합니다.

오버로드

ReleaseHdc()

GraphicsGetHdc() 메서드에 대한 이전 호출에서 얻은 디바이스 컨텍스트 핸들을 해제합니다.

ReleaseHdc(IntPtr)

GraphicsGetHdc() 메서드에 대한 이전 호출에서 얻은 디바이스 컨텍스트 핸들을 해제합니다.

ReleaseHdc()

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

GraphicsGetHdc() 메서드에 대한 이전 호출에서 얻은 디바이스 컨텍스트 핸들을 해제합니다.

public:
 virtual void ReleaseHdc();
public void ReleaseHdc ();
abstract member ReleaseHdc : unit -> unit
override this.ReleaseHdc : unit -> unit
Public Sub ReleaseHdc ()

구현

설명

GetHdcReleaseHdc 가져오고 Windows 디바이스에 대 한 핸들을 해제할 수 있도록 하는 두 가지가 있습니다. Windows 핸들을 완료하면 항상 에 대한 호출 GetHdcReleaseHdc 을 따라야 합니다.

추가 정보

적용 대상

ReleaseHdc(IntPtr)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

GraphicsGetHdc() 메서드에 대한 이전 호출에서 얻은 디바이스 컨텍스트 핸들을 해제합니다.

public:
 void ReleaseHdc(IntPtr hdc);
public void ReleaseHdc (IntPtr hdc);
member this.ReleaseHdc : nativeint -> unit
Public Sub ReleaseHdc (hdc As IntPtr)

매개 변수

hdc
IntPtr

nativeint

GraphicsGetHdc() 메서드에 대한 이전 호출에서 얻은 디바이스 컨텍스트에 대한 핸들입니다.

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse 이 예제에서는 GDI+ 메서드와 동일한 작업을 수행하기 위해 Windows GDI 함수를 호출하는 방법을 보여 줍니다 Graphics . 코드는 다음 작업을 수행합니다.

  • Windows DLL 파일 gdi32.dll 대한 상호 운용성 DllImportAttribute 특성을 정의합니다. 이 DLL은 원하는 GDI 함수를 포함하며 해당 DLL의 함수를 Rectangle 외부로 정의합니다.

  • 빨간색 펜을 만듭니다.

  • 펜을 사용하여 GDI+ DrawRectangle 메서드를 사용하여 화면에 사각형을 그립니다.

  • 내부 포인터 형식 변수를 정의 hdc 형식의 디바이스 컨텍스트에 대 한 핸들을 해당 값을 가져오거나 설정 합니다.

  • GDI Rectangle 함수를 사용하여 화면에 사각형을 그립니다.

  • 나타내는 디바이스 컨텍스트를 해제 합니다 hdc 매개 변수입니다.

private:
   [System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
   static bool Rectangle2( IntPtr hdc, int ulCornerX, int ulCornerY, int lrCornerX, int lrCornerY );

public:
   void GetHdcForGDI2( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ redPen = gcnew Pen( Color::Red,1.0f );

      // 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 );
   }
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool Rectangle2(
    IntPtr hdc,
    int ulCornerX, int ulCornerY,
    int lrCornerX, int lrCornerY);

private 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);
}
<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)> _
Private 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

설명

디바이스 컨텍스트는 출력에 영향을 주는 그래픽 모드뿐만 아니라 그래픽 개체 및 관련 특성 집합을 정의하는 GDI를 기반으로 하는 Windows 구조체입니다.

ReleaseHdc 메서드에 대한 호출은 GetHdc 쌍으로 표시되어야 합니다. 및 ReleaseHdc 메서드 쌍을 GetHdc scope 동안 일반적으로 GDI 함수만 호출합니다. 매개 변수를 생성 hdc 한 의 Graphics GDI+ 메서드에 대한 scope 호출은 오류와 함께 ObjectBusy 실패합니다. 또한 GDI+는 후속 작업에서 매개 변수의 hdc 에 대한 모든 상태 변경 내용을 Graphics 무시합니다.

적용 대상