Scale Properties and Methods VB Help

Now we can look at the properties. and methods that relate to the control’s position and the coordinate system. There are two groups of properties: those that control the size and position of the control and those that affect (and are affected by) the choice of coordinate system.

Width and Height Properties

These two properties determine the actual dimensions of the control and are ways expressed in the units of the container of the control. Suppose you’re placing a PictureBox control on a Form whose coordinate system is the default, twips. The Width and Height properties of the Picture Box control are expressed in twips. If you change the control’s coordinate system, the values of these two properties won’t change. If you resize the control on the Form by dragging its handles with the mouse, the Width and Height properties will change value to reflect the new size of the control. These properties will also change value if you change the container’s coordinate system to reflect the control’s dimensions in the new coordinate system . .

Left “and Top Properties

The Left and Top properties are the coordinates of the control’s upper-left comer, / and they are expressed in the container’s coordinate system. If you change their values, the control is repositioned. They also change value if you change the container’s coordinate system to reflect the control’s position in the new coordinate system.

ScaleMode Property

The ScnleMode property sets (or returns) the-control’s current coordinate system. Set this property to one of the values shown in Table 6.1 to establish a new coordinate system. If you set this property to 0 (User), you must also set the ScaleWidth and ScaleHeight properties. Conversely, if v..iu set the Sca.lcWidth and/or Scalefieight properties, the ScaleMode property is reset to O.

ScaleWidth and ScaleHeight Properties

These two properties are the control’s inner dimensions in units of the current coordinate system. Changing the coordinate system doesn’tchange the size of the control, but it does change the number of units that can fit along the tW6 axes of the control. For example. <1 Picturcllox control pl.Ked on .1 Form that’s 2,R80 twin wide and 2,880 rwips tall is approximatelv tvvo mches WId” and two inches tall.

Its Width and Height properties are 2,880. If you change the FoI’Q1’scoordinate. system to inches; the control won’t be resized, bulits ScaleWidth and ScaleHeight properties will become two (inches). Where the Xcoordinate of the control’s middle point in the previous coor~inate system ~a!? 1,440, it’s now one. You can also assign values to these properties, in which case you’re automatically switching to a userdefined coordinate system (the ScaleMode property is reset to zero).

ScaleLeft and SealeTop Properties

ScaleLeft and ScaleTop are the coordinates of the upper-left comer of the control in a user-defined system of coordinates. Coordinate systems need not start at zero. Sca1eLeftis the minimum value an Xcoordinate can assume. The maximum Xcoordinate is Sca1eLeft+ScaleWidth. Suppose you want to draw an object with dimensions 12 x 10, but you want the Xcoordinate to start at 100 and ‘the Ycoordinate to start at 300. This coordinate system must be defined as follows:

Form1.SealeWidth – 12
Form1.SealeHeight – 10
Form1.SealeLeft – 100
Form1.SealeTop – 300

The Xcoordinates in this system extend from 100 to 112, and the Y coordinates extend from 300 to 310

Scale Method

Using the Scale method is the most convenient way to set up a user-defined coordinate system. It has the following syntax:

Form1.Seale (Xl, Y1) – (X2, Y2)

The.coordinates 0; the upper-left comer of the control are (Xl, V, and (X2, Y2) are the coordinate of the lower-right comer. The Scale method tells Visual Basic that the horizontal dimension of the control is (X2 – XV units and that the vertical dimension is (Y2 – YV units. This is the address space ‘of the control and it doesn’t affect its external dimensions. To set up the game board mentioned earlier, you can call the Scale method as follows:

Form1.Scale’ 0, 0) – (11, 7)

The statement equivalent to the following assignments

(Of course, setting any of the Scale properties resets the ScaleMode to 0, so you don’t have to explicitly set the ScaleMode.)

All properties that begin with the prefix Scale use the u~r-defined coordinate system. Setting any of these properties switches you to a user-defined coordinate system and resets the ScaleMode property to 0 but doesn’t reposition or rescale the control or the Form. Similarly, every time you issue a Scale command such as Picturel.Scale (0, 0) – (11, 7), these four properties change value according to the Scale command’s arguments.

Posted on November 5, 2015 in Drawing with Visual Basic

Share the Story

Back to Top