PictureBox Control for Visual Basic 6.0 Users

The PictureBox control in Visual Basic 6.0 is replaced by the Windows Forms PictureBox control in Visual Basic 2008. The names of some properties, methods, events, and constants are different, and in some cases there are differences in behavior.

Conceptual Differences

PictureBox as a Container

The Visual Basic 6.0 PictureBox control is a container control; in addition to displaying pictures it can be used to group and display other controls.

The Visual Basic 2008 PictureBox control is not a container control; it is only used to display pictures. You can use the new Panel control as a replacement for the PictureBox control where you need a container control.

AutoSize Property

In Visual Basic 6.0, the AutoSize property determines whether a PictureBox control retains its design-time size (AutoSize = False) or is resized dynamically to fit the dimensions of the picture (AutoSize = True).

In Visual Basic 2008, the AutoSize property is replaced by the SizeMode property; in addition to the Normal and AutoSize modes, options are also available to center, stretch, or zoom the picture.

Graphics Properties and Methods

In Visual Basic 6.0, various graphics properties and methods can be used to draw lines, shapes, and text on top of a PictureBox control.

In Visual Basic 2008, controls no longer have graphics properties or methods; you can still draw on top of a PictureBox control using a T:System.Drawing.Graphics object. For more information, see Graphics for Visual Basic 6.0 Users.

Other Differences

In addition, there are numerous conceptual differences that apply to all controls, including differences in data binding, font handling, drag-and-drop functionality, Help support, and more. For more information, see Windows Forms Concepts for Visual Basic 6.0 Users.

Code Changes for the PictureBox Control

The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.

Code Changes for Displaying a Picture

The following code demonstrates how to display a picture in a PictureBox control at run time.

' Visual Basic 6.0
Picture1.Picture = LoadPicture(App.Path & "\somepicture.jpg")
' Visual Basic
PictureBox1.Image = System.Drawing.Bitmap.FromFile( _
  My.Application.Info.DirectoryPath & "\somepicture.jpg")

Code Changes for Clearing a PictureBox Control

The following code demonstrates how to clear a PictureBox control at run time so that no image is displayed.

' Visual Basic 6.0
Picture1.Picture = LoadPicture("")
' Visual BasicIfNot (PictureBox1.Image IsNothing) Then
    PictureBox1.Image.Dispose()
    PictureBox1.Image = NothingEndIf

Code Changes for Drawing on a PictureBox Control

The following code demonstrates how to draw a 40 pixel diameter red circle in the center of a PictureBox control at run time.

' Visual Basic 6.0
Private Sub Picture1_Paint
    Dim x As Integer
    Dim y As Integer
    Picture1.ScaleMode = vbPixels
    x = Picture1.ScaleWidth / 2
    y = Picture1.ScaleHeight / 2
    Picture1.Circle (x, y), 20, vbRed
End Sub
' Visual BasicPrivateSub PictureBox1_Paint(ByVal sender AsObject, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    Dim radius AsInteger = 20
    Dim diameter AsInteger = radius * 2
    Dim x AsInteger = (PictureBox1.Width / 2) - radius
    Dim y AsInteger = (PictureBox1.Height / 2) - radius
    e.Graphics.DrawEllipse(Pens.Red, x, y, diameter, diameter)
EndSub

PictureBox Control Property, Method, and Event Equivalencies

The following tables list Visual Basic 6.0 properties, methods, and events, along with their Visual Basic 2008 equivalents. Those properties, methods, and events that have the same name and behavior are not listed. Where applicable, constants are indented beneath the property or method. All Visual Basic 2008 enumerations map to the System.Windows.Forms namespace unless otherwise noted.

This table provides links to topics explaining behavior differences. Where there is no direct equivalent in Visual Basic 2008, links are provided to topics that present alternatives.

Properties

Visual Basic 6.0

Visual Basic 2008 Equivalent

Align

Dock

Appearance

New implementation. For more information, see Appearance and BorderStyle Properties for Visual Basic 6.0 Users.

AutoRedraw

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

AutoSize

SizeMode

BackColor

BackColor

NoteNote:
Colors are handled differently in Visual Basic 2008. For more information, see Color Behavior for Visual Basic 6.0 Users.

BorderStyle

BorderStyle

NoteNote:
In Visual Basic 6.0, the default is Fixed Single; in Visual Basic 2008 the default is None.

ClipControls

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Container

Parent

CurrentX

CurrentY

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

DataChanged

DataField

DataFormat

DataMember

DataSource

New implementation. For more information, see Data Access for Visual Basic 6.0 Users.

DragIcon

DragMode

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

DrawMode

DrawStyle

DrawWidth

FillColor

FillStyle

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Font

FontBold

FontItalic

FontName

FontSize

FontStrikethrough

FontUnderline

Font

NoteNote:
Fonts are handled differently in Visual Basic 2008. For more information, see Font Object for Visual Basic 6.0 Users.

ForeColor

ForeColor

NoteNote:
Colors are handled differently in Visual Basic 2008. For more information, see Color Behavior for Visual Basic 6.0 Users.

HasDC

HDC

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Height

Height, Size

NoteNote:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.

HelpContextID

New implementation. For more information, see Help Support for Visual Basic 6.0 Users.

HWnd

Handle

Image

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

NoteNote:
In Visual Basic 2008, the Image property is not a graphics property. It is the equivalent of the Visual Basic 6.0 Picture property.

Index

New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users.

Left

Left

NoteNote:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.

LinkItem

LinkMode

LinkTimeOut

LinkTopic

No equivalent. For more information, see Dynamic Data Exchange for Visual Basic 6.0 Users.

MouseIcon

New implementation. For more information, see Cannot set a custom MousePointer.

MousePointer

Cursor

For a list of constants, see MousePointer for Visual Basic 6.0 Users.

OLEDragMode

OLEDropMode

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

Parent

FindForm

Picture

Image

ScaleHeight

ScaleLeft

ScaleMode

ScaleTop

ScaleWidth

New implementation. For more information, see Coordinate System for Visual Basic 6.0 Users.

ToolTipText

ToolTip component

For more information, see ToolTip Support for Visual Basic 6.0 Users.

Top

Top

NoteNote:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.

WhatsThisHelpID

New implementation. For more information, see Help Support for Visual Basic 6.0 Users.

Width

Width, Size

NoteNote:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.

Methods

Visual Basic 6.0

Visual Basic 2008 Equivalent

Circle

Cls

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Drag

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

Line

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

LinkExecute

LinkPoke

LinkRequest

LinkSend

No equivalent. For more information, see Dynamic Data Exchange for Visual Basic 6.0 Users.

Move

SetBounds

NoteNote:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.

OLEDrag

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

PaintPicture

Point

Print

PSet

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Scale

ScaleX

ScaleY

New implementation. For more information, see Coordinate System for Visual Basic 6.0 Users.

SetFocus

Focus

ShowWhatsThis

New implementation. For more information, see Help Support for Visual Basic 6.0 Users.

TextHeight

TextWidth

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

ZOrder

BringToFront or SendToBack method

Events

Visual Basic 6.0

Visual Basic 2008 Equivalent

Change

New implementation. There are individual events (BackgroundImageChanged, SizeChanged, and so forth) that are raised when some properties are changed.

DblClick

DoubleClick

DragDrop

DragOver

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

GotFocus

Enter

KeyDown

KeyPress

KeyUp

New implementation. The Visual Basic 2008 PictureBox control is not a container control and does not receive keystrokes.

LinkClose

LinkError

LinkNotify

LinkOpen

No equivalent. For more information, see Dynamic Data Exchange for Visual Basic 6.0 Users.

LostFocus

Leave

OLECompleteDrag

OLEDragDrop

OLEDragOver

OLEGiveFeedback

OLESetData

OLEStartDrag

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

Validate

Validating

Upgrade Notes

During upgrade, PictureBox controls that contain controls are upgraded to Panel controls. For Visual Basic 6.0 PictureBox controls that were upgraded to Panel controls, images assigned to the Picture property are mapped to the BackgroundPicture property of the Panel control.

See Also

Reference

PictureBox Control Overview (Windows Forms)