This documentation is archived and is not being maintained.

Graphics Changes in Visual Basic .NET

In Visual Basic 6.0, various graphics methods and properties were used to draw on a form or PictureBox control. Graphics in Visual Basic 6.0 were based on Windows Graphics Device Interface (GDI) APIs.

In Visual Basic .NET, graphics are provided by the System.Drawing namespace, which encapsulates the new GDI+ APIs. GDI+ expands upon the graphics capabilities of Visual Basic 6.0, but the methods are not compatible. When an application is upgraded from Visual Basic 6.0, graphics methods are not upgraded.

The following example shows the code used to draw a circle in the upper left corner of a form using Visual Basic 6.0 and Visual Basic .NET:

' Visual Basic 6.0
Private Sub Form_Click()
   ' Set the ScaleMode to pixels.
   Me.ScaleMode = 3
   Me.Circle (50, 50), 50, vbRed
End Sub

' Visual Basic .NET
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
   ' Create a Pen object.
   Dim pen As New Drawing.Pen(System.Drawing.Color.Red, 1)
   Me.CreateGraphics.DrawEllipse(pen, 0, 0, 100, 100)
   Pen.Dispose
End Sub

The following table lists Visual Basic 6.0 graphics properties and methods and their Visual Basic .NET equivalents.

Visual Basic 6.0Visual Basic .NET Equivalent
AutoRedraw PropertyNo equivalent. To persist graphics, put graphics methods in the Paint event.
Circle MethodGraphics.DrawEllipse Method
ClipControls PropertyNo equivalent. To repaint only part of an object, create a clip in the Paint event using the Graphics.SetClip Method method.
Cls MethodGraphics.Clear Method
CurrentX PropertyThe x parameter of various graphics methods. For example, DrawRectangle(pen, x, y, width, height)
CurrentY PropertyThe y parameter of various graphics methods. For example, DrawRectangle(pen, x, y, width, height)
DrawMode PropertyPen.Color Property
DrawStyle PropertyPen.PenType Property
DrawWidth PropertyPen.Width Property
FillColor PropertySolidBrush.Color Property
FillStyle PropertyPen.Brush Property
HasDC PropertyNo equivalent. Device contexts are no longer necessary with GDI+.
HDC PropertyNo equivalent. Device contexts are no longer necessary with GDI+..
Image PropertyImage Property. In Visual Basic 6.0 the Image property returned a handle; in Visual Basic .NET it returns a System.Drawing.Image object.
Line MethodGraphics.DrawLine Method
PaintPicture MethodGraphics.DrawImage Method
Point MethodNo equivalent for forms or controls. For bitmaps, use Bitmap.GetPixel Method.
Print MethodGraphics.DrawString Method
Pset MethodNo equivalent for forms or controls. For bitmaps, use Bitmap.SetPixel Method.
TextHeight PropertyFont.Height Property
TextWidth PropertyGraphics.MeasureString Method

See Also

Creating Graphical Images with GDI+

Show: