SealeX, SealeY Methods” VB Help

On occasion, you’ll want to express the control’s new size in a given coordinate system without changing the container’s coordinate system. Let’s say the Form’s coordinate system is 1 (twips) and you want to place ‘a PictureBox on it with the exact dimensions (;f 1.20 x 2.00 inches. First, calculate how many twips correspond. to 1.20 and 2.00 inches, and then assign these values to the control’s Width and Height properties. Given that there are 1,440 twips in an inch, mapping inches to twips is straightforward. VIsual Basic, however, provides the SealeX and ScaleY methods to convert units between any two coordinate systems. Both methods have the identical syntax, which is:

Forml.ScaleX (width, fromscale, toscale)

The width argument is the number of units you want to convert, fromscale is the coordinate system from which the units will be converted, and toscale is the coordinate system into which the units will be converted, The arguments fromscale and toscale can have one of the values.

Suppose you want to make the Picture1 control 200 pixels wide by 140 pixels tall. The Form on which the PictureBox lies has the default coordinate system, twips. The Width and Height properties of the Picture1 control, therefore) must be expressed in twips. To convert 200 pixels to twips, use the following statement:

WidthTwips – Form1.ScaleX(200,  vbPixels,  vbTwips)

Similarly, to convert the height of 140 pixels to twips, use the following statement:

HeightTwips # form1.ScaleY(140.  vbPixels,  vbTwips)

And then use the results to set the control’s size in twips

Picturel.Width –  WidthTwips
Picturel.Height –  HeightTwips

Since the Form’s coordinate system is twips, you can omit the last argument of the SealeX and Scaley methods: You can resize the Picturel control with the following statements

Picturel.Width = Form1.ScaleX(200,  vbPixels)
Picturel.Height = Form1 .ScaleY(140.  vbPixels):

TWipsPerPixelX, TwipsPerPixelY Properties

These two properties apply to the Screen object, and they return the number of ‘1wips per pixel for an object measured horizonfally (TwipsPerPixelX) or vertically (TwipsPer Pixely)

CurrentX, CurrentY Properties

A basic concept in drawing with Visual Basic methods is the current point. Visual Basic allows you to draw shapes, a line for instance ..without specifying a starting point. If the starting point isn’t specified, the.current point becomes the line’s starting point. After the line is drawn, its endpoint becomes the current point. The properties Currents: and CurrentY set or read the coordinates of the current point in the units of the current coordinate system, To display a string at specific coordinates on a Form, set the Currentx and Current’r properties to the desired coordinates and then issue the Print method to display the string (the Print method is described later ill this chapter).

V86 at Work: The Coords Project

To help you visualize the various coordinate systems and the related properties, have included the Coords project on the CO, which. The Option buttons on the left side of the Form set the ScaleMode of the PictureBox control on the right side. The Picture Box control has fixed dimensions, but you can easily change its-internal coordinate system by clicking one of the Option buttons. Each time you set a new coordinate system, the coordinates of the PictureBox control’s opposite comets are updated. Set a coordinate system, place the pointer over the Picture Box, and’then move it around while holding down the left mouse button. As the pointer slides over the control, its coordinates are displayed.

You can also set your own coordinate system by supplying the proper values in the four TextBox controls in the-lower-left segment of the window. You can use both positive and negative coordinates and then slide the pointer over the PictureBox to see its coordinates. The most interesting part of the Coords application‘s code is in the PictureBox control’s MouseMove event. You can open the Coords application with the Visual Basic editor to find out how it works. You can also interrupt the applicano: I and move or resize the PictureBox control by setting its Top, Left, Height, and Width properties. Thecode for the application manipulates the control’s Scale properties only, and you can’t change the control’s position with these properties. Let’s start by looking at the code of the Option buttons.

Posted on November 5, 2015 in Drawing with Visual Basic

Share the Story

Back to Top
Share This