Graphics.FromHwnd(IntPtr) 메서드

정의

지정된 창 핸들에서 새 Graphics를 만듭니다.

public:
 static System::Drawing::Graphics ^ FromHwnd(IntPtr hwnd);
public static System.Drawing.Graphics FromHwnd (IntPtr hwnd);
static member FromHwnd : nativeint -> System.Drawing.Graphics
Public Shared Function FromHwnd (hwnd As IntPtr) As Graphics

매개 변수

hwnd
IntPtr

nativeint

창에 대한 핸들입니다.

반환

이 메서드는 지정된 창 핸들에 대한 새 Graphics를 반환합니다.

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며, 이벤트 처리기의 매개 변수인 와 예제의 PaintForm 필요합니다PaintEventArgse.thisForm 코드는 다음 작업을 수행합니다.

  • 새 내부 포인터 변수 hwnd 를 만들고 예제 폼의 핸들로 설정합니다.

  • 핸들에서 새 Graphics 를 만듭니다.

  • 빨간색 펜을 사용하여 직사각형을 새 Graphics 에 그립니다.

  • Graphics를 삭제합니다.

public:
   void FromHwndHwnd( PaintEventArgs^ /*e*/ )
   {
      // Get handle to form.
      IntPtr hwnd = this->Handle;

      // Create new graphics object using handle to window.
      Graphics^ newGraphics = Graphics::FromHwnd( hwnd );

      // Draw rectangle to screen.
      newGraphics->DrawRectangle( gcnew Pen( Color::Red,3.0f ), 0, 0, 200, 100 );

      // Dispose of new graphics.
      delete newGraphics;
   }
private void FromHwndHwnd(PaintEventArgs e)
{

    // Get handle to form.
    IntPtr hwnd = this.Handle;

    // Create new graphics object using handle to window.
    Graphics newGraphics = Graphics.FromHwnd(hwnd);

    // Draw rectangle to screen.
    newGraphics.DrawRectangle(new Pen(Color.Red, 3), 0, 0, 200, 100);

    // Dispose of new graphics.
    newGraphics.Dispose();
}
Private Sub FromHwndHwnd(ByVal e As PaintEventArgs)

    ' Get handle to form.
    Dim hwnd As IntPtr = Me.Handle


    ' Create new graphics object using handle to window.
    Dim newGraphics As Graphics = Graphics.FromHwnd(hwnd)

    ' Draw rectangle to screen.
    newGraphics.DrawRectangle(New Pen(Color.Red, 3), 0, 0, 200, 100)

    ' Dispose of new graphics.
    newGraphics.Dispose()
End Sub

설명

항상 메서드를 호출하여 메서드에서 DisposeGraphics 만든 FromHwnd 및 관련 리소스를 해제해야 합니다.

적용 대상