VB length width height unit, width,scalewidth,height,scaleheight,scalemode

Source: Internet
Author: User
Tags constant extend

How to understand the relationship between the scale class attribute and the width height property in VB Forms
VB in the Scalehiegt,scalewidth, and the form of the width,height difference and relationship is difficult for many VB beginners to understand. I was in the process of learning Delphi has been not clear about this kind of introduction, but through the VB in these similar concepts of learning, can be said to have mastered this concept and principle. Now look back to Delphi's relevant knowledge points have a sense of enlightened, VB is indeed the best language for the introduction of visual programming.

The question is raised
In VB, the default unit of measure is twips, which is a unit of measurement independent of screen resolution, mainly used on the printer, about 1 twips =1/20 lbs. See MSDN for some other units. Using twips will give us some trouble because we are used to measuring the size of forms and controls using pixels, and using the current resolution of the Monitor as a reference to determine the proper size of the form, how can we determine the correct value when we want to dynamically change the size of the form, to move the controls in the form dynamically, How to determine the position of the control. At the same time, there are some properties in the VB form: Scalewidth,scaleheight,scaleleft,scaletop,scalemode,width,height, what's the relationship between them, How is the size of the controls in the form affected? With the explanations below, we will be able to solve the problems mentioned above.

In VB in the form of the inside (except the form border and the area of the title bar) has a similar to the canvas, it is always full of the entire form region, he has a coordinate system, the default is the original point is the form of the upper left corner, the coordinates are 0,0 and then left to extend the X axis, down is the y axis, But the unit of this coordinate is the default is twips, of course, we can be modified to other types of units, to modify the unit of measure to set the form's ScaleMode property. such as: set to Pixel scalemode=3. This coordinate system is used to determine where to place the plot by means of print, and to determine where in the container to place the control, as well as the ratio of the form width to height.
VB uses a total of 8 units of measurement. The system default unit of measurement is twips (twip,1 cm = 576 twips), and the user can select other standard units of measurement provided by the system as needed. The setting of the unit of measure is defined by the ScaleMode property of the form or picture frame. Its attribute value and corresponding unit of measure and usage are shown in table 9-1-1.
Table 9-1-1 VB Unit of Measure
attribute value Word constant description
0 vbuser user Custom type. If the user uses ScaleWidth, ScaleHeight, ScaleTop, scaleleft set coordinate system, VB will automatically set ScaleMode to 0
1 vbtwips default value, in TWIP units. 1 "=144 Twip
2 vbpoints in points (point), 1 inches = 72 lbs
3 vbpixels pixels (Pixel), which is the smallest unit of display resolution.
4 vbcharacters character, 1 character width =120 twip,1 character height =240 Twip
5 vbinches inches
6 vbmillimeters mm
7 Vbcentimeters cm
Description
⑴ The above table, in addition to 0 and 3, the remaining specifications are available for the printer, the unit length used is the length of the output on the printer.
The ⑵scalemode property can be set in the Properties window at design time or through program code. For example:
Form1.scalemode=5 ' form coordinate system in inches
Picture1.scalemode=7 ' picture frame coordinate system in centimeters

Pre-knowledge
In VB in the form of the inside (except the form border and the area of the title bar) has a similar to the canvas, it is always full of the entire form region, he has a coordinate system, the default is the original point is the form of the upper left corner, the coordinates are 0,0 and then left to extend the X axis, down is the y axis, But the unit of this coordinate is the default is twips, of course, we can be modified to other types of units, to modify the unit of measure to set the form's ScaleMode property. such as: set to Pixel scalemode=3. This coordinate system is used to determine where to place the plot by means of print, and to determine where in the container to place the control, as well as the ratio of the form width to height.

The function of the scale class attribute
Now that the form has such a canvas and its coordinates, let's take a look at the properties of the coordinate system. These scale type properties are primarily used to set the value of the canvas coordinate system to the height-to-width value of the form. Specifically how the relationship and how the impact of the following is a discourse. Scaleleft,scaletop These two properties are used to set the origin of this coordinate system, the system default Scaleleft,scaletop is 0, that is, the origin is in the upper left corner of the form, the coordinate system is only greater than 0 of that piece of coordinates, The benefit is that the coordinate system can be intuitively used because the reference point is 0 and starts from the upper-left corner of the form. If these two values are set to greater than 0, the coordinates of the canvas have positive and negative areas, which is more like our mathematical coordinate system. The ScaleMode is used to set the unit of measure for the axis.


The role of Width,height
These two properties are used to set the width and height of the form, their units are always twips, will directly affect the size of the canvas and coordinates of the situation, to dynamically set the size of the form can only be set by these two properties.


The relationships of these attributes
By default, the width and height of a form is the same size as the width and height of the canvas on the form, and the coordinate origin of the canvas is the upper-left corner of the form. That is, the width of the canvas and the form is 1:1, meaning that the canvas has a width of 1 twips equal to the 1 twips of the form. So when we use Print.circle (500,500) on the form, 200来 draws a circle, the origin is 500 twips from the top of the form, 500 twips on the left, and a radius of 200 twips. Now we try to change the form of the Scaleheight,scalewidth to the original 1/2, and now also use the same method to draw a circle, compared to the This look now the circle with the change before the circle, you can find the radius of the current circle than the original expansion of one times, and the position of the center has changed. Why do the same parameters have different results? This is the role of ScaleHeight ScaleWidth, if the original width of the form is 1000 twips, ScaleWidth is 1000 twips, that is, they are 1:1 of the relationship, we use Print.circle (500,500), 200 the drawing on the canvas of the size of the circle is 1:1, a clear point is that the canvas width of a twips is a form of the width of a twips, but modified scalewidth, such as the original value of half, the situation is not the same, the canvas and the proportion of the form becomes 1:2, in the canvas view, To use half of the original value to represent the width of the form, then it can only be 1 twips to represent the form width of two twips, so if the original parameter to use the Print method to make a circle, the circle is twice times the original. It's kind of like trying to draw the whole map of China on a white sheet, and a millimeter on the sheet is equivalent to 108,000 kilometres. This is where the scale attribute is width,height or related to the form.


The relationship between twips and pixels
We can return the TWIPPERPIXERSX and TWIPPERPIXERSX properties of the screen to the current resolution by the VB system, which should be 15 by default. But this value is not fixed. The answer is no, the screen is also a canvas, as well as the form has a high and wide, to return 15 of the precondition is scalewidth with width is 1:1,scaleheight and height is also 1:1.
Summary
     There is a canvas on the form whose coordinate system defaults to the form, but can be modified by the scale class property. By these scale class properties we can develop a program with the function of zooming in and out, as long as the parameters of the drawing method are kept constant, the dynamic change of the scale attribute can achieve the goal, the relationship is inversely proportional, that is, the parameter is unchanged, the scale decreases then the graph enlarges. Examples of such programs are like volume charts in stock analysis software.
     Another: Delphi also has a similar canvas mechanism. The principle is basically the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.