Graphics.FromHwnd(IntPtr) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
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
Pencereye tutamaç.
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 thisForm
Paint bir parametresi olan ve örneğin parametresi olan öğesini Form gerektirirPaintEventArgse
. 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 bir dikdörtgen çizer.
Yeni Graphicsöğesini atılır.
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
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin