How to understand the relationship between the scale class attribute and the width height attribute in vb form

Source: Internet
Author: User

from: Blog.csdn.net/lizanhong

How to understand the scale class properties in VB Forms
and width height properties of the relationship between

The Scalehiegt,scalewidth of VB and the difference between the width,height in the form and the relation are difficult to understand by many VB beginners. I am in the process of learning Delphi has also been a similar introduction to do not know, but through the VB in these similar concepts of learning, can be said to have mastered the concept and principle. Now look back to see the relevant knowledge of Delphi has suddenly enlightened feeling, VB is indeed the best language for the introduction of visual programming.


The question of the proposed
The default unit of measurement in VB is twips, a unit of measure unrelated to screen resolution, mainly used on the printer, probably 1 twips =1/20 pounds. For some other units, check out MSDN. Using twips can cause us some trouble because we're all used to measuring the size of forms and controls using pixels, and use the current resolution of the Monitor as a reference to determine the appropriate size of the form, when we want to dynamically change the size of the form, how do we determine the correct number, we want to dynamically move the controls in the form, How to determine the position of the control. At the same time, there are some properties in the form of VB: Scalewidth,scaleheight,scaleleft,scaletop,scalemode,width,height, what is the relationship between them, How it affects the size of controls in a form. With the following explanation, we can solve the problem mentioned above.


Preliminary knowledge
In fact, in the form of VB (except the border of the form and the area of the title bar) there is something similar to the canvas, it always fills the entire form region, he has a coordinate system, the default is the original point is the top left corner of the form, coordinates are 0,0 then to the left of the x axis, down is the y axis, But this coordinate unit default is twips, of course, we can be modified to other types of units, to modify the unit of measurement to set the form of the ScaleMode property. For example: set to Pixel scalemode=3. This coordinate system is used to determine where to draw by print and so on, and to determine where to place the control in the container, as well as the ratio of the width and height of the form.

The role of scale class attributes
Once the form has such a canvas and its coordinates, let's take a look at the properties of the coordinate system. These scale type attributes are used primarily to set the value of the canvas coordinate system with the form's high-wide numerical proportions. What is the relationship and how it affects the following essays. Scaleleft,scaletop These two properties are used to set the origin of the coordinate system, the default scaleleft,scaletop is 0, that is, the origin in the upper left corner of the form, the coordinate system is only more than 0 of the coordinates, The advantage is that you can use this coordinate system intuitively because the reference point is 0 and starts at the upper-left corner of the form. If you set these two values to be greater than 0, the canvas coordinates have positive and negative areas, which is more like our mathematical coordinate system. ScaleMode is used to set the unit of measure for an 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 the proportion of the coordinates, to dynamically set the size of the form can only be set by these two properties.

The relationships of these properties
By default, the width and height of a form are the same as the width and height of the canvas on the form, and the canvas's coordinate origin is the upper-left corner of the form. That is, the width of the canvas width is 1:1, which means the 1 twips width of the canvas corresponds to the 1 twips width of the form. So when we use Print.circle (500,500) on the form, 200来 draw a circle, the origin is in 500 twips from the top of the form, 500 twips to the left, and 200 twips in the radius. Now we try to change the scaleheight,scalewidth on the form to the original 1/2, now is also the same way to draw a circle, compared to clatter now circle with the change before the circle, you can find that the current circle radius than the original expansion of one times, and the position of the center also changed. Why do the same parameters have different results? This is the role of Scaleheigh ScaleWidth, if the form of the original width is 1000 twips, ScaleWidth is 1000 twips, that is, they are 1:1 of the relationship, we use Print.circle (500,500), 200 the size unit of the circle drawn on the canvas is 1:1, the clear point is that the width of the canvas in a twips is the form 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 will become 1:2, in the canvas view, To use half of the original value to represent the width of the form, then only 1 twips to represent the form width of the two twips, so if you use the original parameters of the Print method to make a circle, the coming out of 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 the equivalent of 108,000 kilometers. This is the relationship between the scale property and the form Width,height.

The relationship between twips and pixels
We can use the VB system of TWIPPERPIXERSX and TWIPPERPIXERSX properties like screen to return the current resolution of each pixel Jian Ti, by default, should be 15. But this value is not fixed. The answer is no, the screen is also a canvas, but also like the form has a high and wide, to return 15 of the prerequisite is scalewidth and width is 1:1,scaleheight and height is also 1:1.

Summarize
The form has a canvas whose coordinate system defaults to the form, but can be modified by scale class properties. Through these scale class properties, we can develop a program with the function of graphics amplification, as long as the parameters of the drawing method are kept unchanged and the scale properties can be changed dynamically, the relationship is inversely proportional, that is to say, the parameter is invariable, and the figure of scale is enlarged. Examples of such programs are the volume diagrams in stock analysis software.

Another: Delphi also has a similar canvas mechanism. The principle is basically consistent.

PS: In VB feel really not accustomed to.

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.