Graphics.FromHwnd(IntPtr) Yöntem

Tanım

Belirtilen tanıtıcıdan pencereye yeni Graphics bir oluşturur.

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

Parametreler

hwnd
IntPtr

nativeint

Pencere tutamacı.

Döndürülenler

Bu yöntem, belirtilen pencere tanıtıcısı için yeni Graphics bir döndürür.

Örnekler

Aşağıdaki kod örneği, Windows Forms ile kullanılmak üzere tasarlanmıştır ve olay işleyicisinin bir parametresi olan ve örneğin parametresi olan Form öğesini gerektirirPaintEventArgse.PaintthisForm Kod aşağıdaki eylemleri gerçekleştirir:

  • Yeni bir iç işaretçi değişkeni hwnd oluşturur ve örnek formunun tutamacını ayarlar.

  • Tanıtıcıdan yeni Graphics bir oluşturur.

  • Kırmızı kalem kullanarak yeniye Graphics dikdörtgen çizer.

  • Yeni Graphicsöğesini atıyor.

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

Açıklamalar

yöntemi tarafından FromHwnd oluşturulan ve ilgili kaynakları serbest bırakmak Graphics için her zaman yöntemini çağırmalısınızDispose.

Şunlara uygulanır