-
Nov 10th, 2019, 01:41 PM
#1
Thread Starter
Addicted Member
Units of width and height in VB6/VS6?
I have never worked serious projects in VB6 so I cannot brag about it. One thing that baffles me is the number that is placed in the property sheet of the current VB6 form I work on.
Width has value of 9724 and height is 6448 which doesn't seem to be pixels since the form is like 800 by 600 screen pixels.
What is the name of the display units in VB6 and how can I translate those values to number of pixels on screen?
-
Nov 10th, 2019, 01:52 PM
#2
Re: Units of width and height in VB6/VS6?
Most objects that are containers (forms, pictureboxes, usercontrols) have a scalemode property: pixels, twips, inches, centimeters, etc. While in design (or @ runtime), changing the scalemode property changes values based on the scalemode.
Controls placed in the container reflect their positions/dimensions in the container's scalemode. Their events X,Y parameters are in that scalemode. If the container has no scalemode property, twips is the default. OCXs may be different.
So 9724 is likely 648 pixels if scalemode is twips & form is being designed at normal 96 DPI.
VB6 has two functions for converting values between scalemodes: ScaleX & ScaleY. These are methods available from forms, pictureboxes, usercontrols.
Code:
Debug.Print ScaleX(9724, vbTwips, vbPixels)
This should get you started.
-
Nov 10th, 2019, 07:20 PM
#3
Re: Units of width and height in VB6/VS6?
Originally Posted by kutlesh
Width has value of 9724 and height is 6448 which doesn't seem to be pixels since the form is like 800 by 600 screen pixels.
According to Height, Width Properties:
Originally Posted by MSDN
For Form, Printer, and Screen objects, these properties are always measured in twips.
Originally Posted by kutlesh
What is the name of the display units in VB6 ...
It's called Twip.
Originally Posted by kutlesh
... and how can I translate those values to number of pixels on screen?
You could also use the Screen object's TwipsPerPixelX & TwipsPerPixelY properties.
Code:
Private Sub Form_Load()
MsgBox (Width / Screen.TwipsPerPixelX) & " x " & (Height / Screen.TwipsPerPixelY), vbInformation
End Sub
-
Nov 11th, 2019, 09:37 AM
#4
Re: Units of width and height in VB6/VS6?
Originally Visual Basic was a merger of Microsoft's BASIC language with a Windows Form generation tool written by another party. As the standard for print measurement was based on Points, i.e. 72 points per inch of paper, the original developer wanted a scale that mapped directly to points, but with finer resolution than points, so chose to divide the point into TWenty parts, so called it twips meaing a TWentieth Interval of Point (or something to that effect).
So, if you draw out a line on paper, you should have 20x72 or 1440 twips per inch of paper. Given that printers of the day were usually 300 dpi to 600 dip, with some maybe 1200 dpi, the 1440 dpi was considered more than precise enough for laying out accurate forms for printing. Also, back in the day, monitors were generally mapped to a couple of common resolutions, i.e. 96 dpi and 120 dpi, so the TwipsPerPixel values were correspondingly 15 (15 * 96 = 1440) or 12 (12 * 120 = 1440). Those were the good old days, when DPI resolution were an easy thing to account for.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|