Graphics in VB.NET using Handle

This article shows you how to draw Graphics using Handle in VB.NET.
  • 4660

Handle Graphics will allow us to design GUI for the program or create graphics. Handle Graphics refers to collection of low level graphics functions that are used to generate the graphics. Note these features are primitive compared to VB but they are reasonable and sufficient from a technical computation point of view. Here you will see how draw graphics in VB.NET using Handles:

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 Trapezoi
 
       G.DrawPolygon(New Pen(Color.Blue), points)
   End Sub
   Public Sub New()
        MyBase.New()
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    End Sub
End Class

OUTPUT:
 

graphic.gif

NOTE:
  You can also manipulate graphics by stretching, copying and transforming images.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.