Udostępnij za pośrednictwem


Coordinate System for Visual Basic 6.0 Users

The coordinates for forms and controls are expressed differently in Visual Basic 2008 than in Visual Basic 6.0; methods for sizing and moving forms differ as well.

Conceptual Differences

In Visual Basic 6.0, coordinates for forms and controls are expressed in twips. In Visual Basic 2008, coordinates are expressed in pixels.

Height and Width Properties

In Visual Basic 6.0, the Height and Width properties are used to change the size of a form or control. Visual Basic 2008 provides a Size property that also allows you to change both height and width in a single step.

Move Method

Visual Basic 6.0 uses the Move method to change the location of a form or control at run time. In Visual Basic 2008, Move is replaced by the SetBounds method and coordinates are expressed in pixels.

ScaleMode property

Visual Basic 6.0 also provides a ScaleMode property you can use to define a different coordinate system. Visual Basic 2008 only supports a single coordinate system, pixels. ScaleMode and its related properties and methods (Scale, ScaleHeight, ScaleLeft, ScaleTop, ScaleWidth, ScaleX, ScaleY) are not supported in Visual Basic 2008. For more information, see ScaleMode is not supported.

Code Changes for Coordinates

The following code illustrates the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.

Resizing a Form

The following example shows how to change the size of a form at run time.

' Visual Basic 6.0
' Measurements are in twips.
Me.Width = 8000
Me.Height = 6000
' Visual Basic' Measurements are in pixels.Me.Size = New System.Drawing.Size(640, 480)

Moving a Control

The following example shows how to move a control at run time.

' Visual Basic 6.0
' Move and retain original size.
CommandButton2.Move 2000, 1000
' Move and resize to 1200 by 800 twips.
CommandButton1.Move 0, 0, 1200, 800
' Visual Basic' Move and retain original size.
Button2.SetBounds(20, 10, 0, 0, BoundsSpecified.X Or BoundsSpecified.Y)
' Move and resize to 120 by 80 pixels.
Button1.SetBounds(0, 0, 120, 80)

Upgrade Notes

When a Visual Basic 6.0 application is upgraded to Visual Basic 2008, the Height and Width properties of forms and controls are automatically converted to pixels.

If the original application used the ScaleMode property, the upgrade tool assumes that the design-time setting for the ScaleMode property was twips; if this is not the case, the conversion will be incorrect and must be fixed. For more information, see ScaleMode is not supported.

See Also

Concepts

Form Object for Visual Basic 6.0 Users

Other Resources

Windows Forms Controls for Visual Basic 6.0 Users

Control Property, Method, and Event Changes for Visual Basic 6.0 Users