Graphics.FromHwnd(IntPtr) Graphics.FromHwnd(IntPtr) Graphics.FromHwnd(IntPtr) Graphics.FromHwnd(IntPtr) Method

정의

지정된 창 핸들에서 새 Graphics를 만듭니다.Creates a new Graphics from the specified handle to a window.

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 IntPtr IntPtr IntPtr

창 핸들입니다.Handle to a window.

반환

이 메서드는 지정된 창 핸들에 대한 새 Graphics를 반환합니다.This method returns a new Graphics for the specified window handle.

예제

다음 코드 예제는 Windows Forms에서 사용 하도록 설계 되었으며 필요 PaintEventArgs e의 매개 변수인를 Paint 이벤트 처리기 뿐만 thisForm, Form 예입니다.The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler, as well as thisForm, the Form for the example. 이 코드에서는 다음 작업을 수행합니다.The code performs the following actions:

  • 새 내부 포인터 변수를 만들고 hwnd 예제 폼의 핸들을 설정 합니다.Creates a new internal pointer variable hwnd and sets it to the handle of the example's form.

  • Graphics 핸들에서 합니다.Creates a new Graphics from the handle.

  • 새 사각형을 그립니다 Graphics 빨간색 펜을 사용 합니다.Draws a rectangle to the new Graphics using a red pen.

  • 새 삭제 Graphics합니다.Disposes the new 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

설명

항상 호출 해야 합니다 Dispose 해제 하는 메서드에 Graphics 및 관련 된 리소스에서 만든를 FromHwnd 메서드.You should always call the Dispose method to release the Graphics and related resources created by the FromHwnd method.

보안

SecurityPermission
비관리 코드에 액세스 합니다.for access to unmanaged code. 열거형 관련: UnmanagedCode합니다.Related enumeration: UnmanagedCode.

적용 대상