Graphics.FromHwnd(IntPtr) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Crea un nuovo Graphics dall'handle specificato a una finestra.
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
Parametri
- hwnd
-
IntPtr
nativeint
Handle in una finestra.
Restituisce
Questo metodo restituisce un nuovo Graphics per l'handle di finestra specificato.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Form e richiede PaintEventArgse, che è un parametro del gestore eventi Paint, nonché thisForm, il Form per l'esempio. Il codice esegue le azioni seguenti:
Crea una nuova variabile puntatore interna
hwnde la imposta sull'handle del form dell'esempio.Crea un nuovo Graphics dall'handle.
Disegna un rettangolo al nuovo Graphics utilizzando una penna rossa.
Elimina il nuovo 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
Commenti
È consigliabile chiamare sempre il metodo Dispose per rilasciare il Graphics e le risorse correlate create dal metodo FromHwnd.