Several VB6 objects, specifically the Form, PictureBox, and Printer, have a coordinate system that is used for positioning other objects within them. For example, a Command Button's Top and Left properties determine its position within the form's coordinate system. By default, the coordinate system employs units of twips, equal to 1/1440 of an inch, with the origin (the 0,0 point) in the top left corner. The X coordinate increases to the right, and the Y coordinate increases down.
However, there may be times when you may want to modify the screen coordinates. Changing the scale of a form or other object is useful in graphical applications where you want the positioning units to be a match to the actual data the program is working with.
To change the unit of measurement without affecting the origin, set the ScaleMode property. Your choices are defined by these VB constants, most of which are self-explanatory:
vbUser (custom, more on this soon)
vbPoints (a printer's unit, one point = 1/72 inch)
vbCharacters (120 twips horizontally, 240 vertically)
You can also move the origin and change the axis direction using the Scale method. Here are its arguments:
Scale(x1, y1)-(x2, y2)
- X1 and Y1 are the new coordinates of the top left corner of the object.
- X2 and Y2 are the new coordinates of the bottom right corner of the object.
Let's look at some examples. This call leaves the origin at the top left corner but changes to coordinate units to be 1/100 of the form's size:
This call moves the origin to the lower left corner of the form and inverts the Y axis to that positive values move upward:
This call moves the origin to the center of the form with the Y axis inverted and units equal to 1/5000 of the form size: