Mega Code Archive

 
Categories / VB.Net Tutorial / 2D Graphics
 

Create Graphics from Handle

Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class GraphicsFromHwnd    public Shared Sub Main         Application.Run(New Form1)    End Sub End class public class Form1   Inherits System.Windows.Forms.Form   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)         Dim G As System.Drawing.Graphics = Graphics.FromHwnd(Me.Handle)         Dim points(3) As System.Drawing.Point         points(0) = New Point(120, 60) 'Top Left of Trapezoid         points(1) = New Point(180, 60) 'Top Right of Trapezoid         points(2) = New Point(240, 120) 'Bottom Right of Trapezoid         points(3) = New Point(60, 120) 'Bottom Left of Trapezoid         G.DrawPolygon(New Pen(Color.Blue), points)   End Sub   Public Sub New()         MyBase.New()     Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)     Me.ClientSize = New System.Drawing.Size(292, 273)     Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen   End Sub End Class