How to understand the relationship between Scale class properties and width height attributes in the VB form.

zhaozj2021-02-16  54

Keywords: coordinate system scale width drawing pixel

Scalehiegt, ScaleWidth in VB, the difference and relationship between Width, HEIGHT in the form is difficult to understand many VB beginners. I have been unclear from this similar introduction in learning Delphi, but after learning these similar concepts in VB, it can be said that this concept and principle have been mastered. Now look back at Delphi's related knowledge points, there is a sudden feeling, VB is indeed the best language for visual programming.

The problem is proposed in the VB, which is a metric unit that is independent of the screen resolution, mainly in the printer, probably 1 = = 1/20 pounds. Please check the MSDN in some other units. Using will bring us some trouble, because we are all accustomed to using the pixel metric form and control size, and use the display of the current resolution to determine the appropriate size of the form, when we want to dynamically When changing the size of the form, how should we determine the correct value, want to move the control in the form, how to determine the location of the control? At the same time, there are some properties in the VB form: ScaleWidth, ScaleHeight, Scaleleft, Scaletop, Scalemode, Width, Height, how does the relationship between them affect the size of the controls in the form? Through the following explanation, we can solve the problems mentioned above.

Preliminary knowledge is actually in the form of the form in VB (in the area of ​​the form border and the title bar), there is something similar to the canvas, which is always full of the entire form area, he has a coordinate system, the default is The origin is the upper left corner of the form, the coordinates are 0, 0 and then extended to the left is the x-axis. The next is the Y axis, but the unit of this coordinate is the default. Of course we can modify other types of units. To modify the measure unit, set the form of the ScaleMode property. Such as: set to pixels scalemode = 3. This coordinate system is used to determine what is the way to make a way through Print, and to place the control in what location in this container, and the proportion of the form wide and high.

Scale class properties The role of the class clearly has such a canvas and its coordinates, let's take a look at the properties of this coordinate system. These Scale type properties are mainly used to set the value of the value of the canvas coordinate system with the high and wide value of the form. What is the specific relationship and how impact is said below. SCALELEFT, SCALETOP These two attributes are used to set the origin position of this coordinate system, the system default schelaleft, scaletop is 0, that is, the origin is in the upper left corner of the form, the coordinate system is only greater than 0 coordinates The benefit is that this coordinate system can be intuitively use because the reference point is 0 and is starting from the upper left corner of the form. If these two values ​​are set to greater than 0, the coordinates of the canvas have a positive and negative area, which is more like our mathematical coordinate system. ScaleMode is used to set the metric unit of the coordinate axis.

Width, Height's role These two attributes are used to set the width and high of the form, and their units are always, they will directly affect the size of the canvas and the proportion of coordinates, to dynamically set the form of the form. Can be set by these two attributes.

The relationship between these attributes is default, the width and high of the form is the same size as the width and high of the canvas on the form, and the coordinate original of the canvas is the upper left corner of the form. That is, the width of the canvas and the relationship of the form of the form is 1: 1, that is, the 1 缇 width of the canvas is equivalent to the 1 缇 width of the form. So when we draw a circle with Print.Circle (500, 500) and 200 on the form, the origin is 500 缇 at the top of the window, 500 octures left, and the radius is 200 缇. Now we try to modify the scaleheight on the form to the original 1/2, now use the same method to draw a circle, compare the circle before the revision, you can find the current radius of the current round than original It has been doubled, and the position of the center has also changed. Why is there anything about the same parameter? This is the role of ScaleHeigh Scalewidth. If the original Width is 1000 缇, ScaleWidth is also 1000 o'clock, that is, they are 1: 1 relationship, we use Print.Circle (500, 500), 200 in the canvas The size unit used by the circle is 1: 1, it is clear that it is a top-width in the canvas. However, after SCALEWIDTH, if it is half the original value, the situation is Not the same, the proportion of the canvas is 1: 2, in the viewing, to use the original value half to indicate the width of the form, then only 1 缇 来 来 表示 " Two, if such a Print method is used for a round, if it is still used by the original parameters, the round is twice the original. The situation is a bit like to draw the entire China map on a white Zhang, which is equivalent to the actual one hundred thousand kilometers. This is the scale property and the form width, Height or the relationship.缇 跟 像 关 关 我们 b 对 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇 缇But is this value fixed? The answer is not, the screen is also a canvas, and it is also as high and wide as the form. The prerequisite for returning 15 is SCALEWIDTH and Width is 1: 1, ScaleHeight and Height are also 1: 1.

There is a canvas on the summary form, and its coordinate system is the same as the form, but can be modified by scale class properties. Through these scale class properties, we can develop a program with a graphic zoom and reduction, as long as the parameters in the mapping are constant, dynamically change the scale attribute to achieve the purpose, this relationship is inversely, that is Said that the parameter is unchanged, and the scale is reduced. Examples of such programs are like a volume map in stock analysis software.

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

转载请注明原文地址:https://www.9cbs.com/read-17815.html

New Post(0)