C ++ Builder first learning and answer (eight)

zhaozj2021-02-16  46

(Copyright Notice: This series is only available for 9CBS only, and also authorized ccrun reprinted, other individuals are not reproduced without the author or 9CBS consent, extracted)

8. Graphics components

59) Q: Windows is a graphics system, how does C Builder processes graphics?

Answer: C Builder processes graphics by providing graphics components, in which commonly used image components, geometric graphics components (Shape), and PaintBoxs. The first two components are located in the Additional page, and the disciplines are located in the System page.

In BCB, Form, Image, Bitmap, Paintbox, etc. have drawing capabilities, which are canvas attributes in these components.

60) Q: What special properties do you have in image controls?

A: The image component can display graphics that stored on a disk in a file form. It has some special properties.

AutoSize properties, when the property value is TRUE, the image component automatically adjusts the size to adapt to the size of the image component. The default is TRUE.

Attribute, when this property is TRUE, the size of the image is automatically adjusted and fills the entire image component. But the ICO file cannot produce this effect. The default is false.

The Transparent property determines if the color is transparent in the image, thereby displays the object below the component. The default is false.

CENTER attribute, when this property is TRUE, the image is displayed in the image; otherwise, from the upper left corner.

Property Picture, you can use this property in the design phase to specify the image you want to display or you can display it during operation. In one case, you can click the omit button in the Value column of the Picture property, and a picture editing dialog box appears, click the LOAD button in the dialog to select the image to display.

61) Q: What should I do if I load a picture during the program run?

A: If you load a picture during the program run, you can use the TPICTure class to loadFromFile, which can load the image file stored on the disk. For example, to load the Picture.BMP under the root directory of the D drive, you can call:

Image1-> Picture-> LoadFromFile ("D: //Picture.bmp");

The type of image file that can be handable this control is: .bmp file, .ico file, .emf and .wmf and other image files. If you try to load an unrecognized file type, an exception error will occur.

62) Q: Can you tell the difference between Autozie and Stretch?

A: Ok, on the form, two image components are placed, and the autosize property of the image component on the left is True, so after loading any picture, the size of the component is identical to the size of the image. And if you increase or reduce the size of the image component, the display of the picture is still constant. Set the AutoSize property of the image component on the right to false and set it to True. When you increase or reduce the size of the image component, the picture will increase or shrink according to the proportion, that is, the picture is always full of components.

63) Q: What is important attributes in the TSHAPE control?

A: This component can display some common geometry, such as rectangles, circles, ellipses, and the like. Geometric graphics components have several important properties: Brush, Pen and Shape. The brush property is used to set the fill feature inside the geometry, including the filled pattern (style) and color (color).

The PEN property is used to set the outer frame characteristics of the geometry, including the color (color), linear and line width (Width) and MODE relationships.

The property shape is used to point out the displayed geometry type. This attribute can have six different values, indicating six different geometric patterns, respectively;

(1) Stellipse represents an ellipse.

(2) Strectangle represents a rectangle.

(3) StroundRect represents the rounded rectangle.

(4) Stroundquare represents the rounded square.

(5) STSQUARE represents a square.

(6) stcircle represents the circle.

In the design phase, you can use the mouse to change the size of the graphic. During operation, the size of the graph can be changed via Height and Width attributes.

64) Q: There is a plus in front of the attribute brush, what does it mean?

A: It indicates that this property can be expanded, that is, it also contains some subviews. Click the plus sign, you can find that its subtribraclege is: Color and Style.

The Color property contains a series of C Builder predefined colors that you can select a fill color from which the geometry shown.

The Style property determines the fill style of the geometry, which can be taken as 8 values ​​separately: BSBDiagonal, Bsclear, Bscross, Bsdiagcross, BSDiagonal, Bshorizontal, Bssolid, and BSvertical.

Attribute Pen is also as sub-properties as attribute BRUSH. Its child property is Color, Mode, Style and Width. The most commonly used is Style and Width, which represent linear and wire width, respectively. Sub property style can take such a value to draw the border:

Pssolid represents a solid line. PSDash expressed a broken number. Psdot represents a dot. Psdashdot represents a broken number and a dot. Psdashdotdot represents a broken number, a dot, a dot. Psclear means no line. PsinsideFrame represents the inner frame.

65) Q: What is the role of this drawing board?

A: The discipline assembly is mainly provided by the user, and the user can draw a variety of different graphics in this mapping area using a plot statement.

It should be noted that because the discipline components do not have a boundary, it is usually placed on a bounded container component component.

The drawing board components mainly use the Canvas attribute to draw a drawing. Canvas (Canvas) is an object of class Tcanvas, class Tcanvas contains various methods and properties used in the drawing. Below we first introduce the various properties of the Canvas object.

The Pen Canvas object has a brush member, which determines the type of brush used when drawing geometry. Just now, we introduced the line and line width of the brush.

The Color property of the brush is the foreground color used when drawing.

The properties of the brush are used to determine the painted method of the brush and the original on the screen. The color of the line segment can be redirected in conjunction with the current color, the color of the screen, or their reverse value. But do not change the Color property.

It can take such a value:

PMBLACK: indicates a black drawing;

PMWHITE: Indicates with a white drawing; PMNOT: The color of the painted point drawn is opposite to the original colors;

PMCopy: Drawing of a color drawing defined in the Color property.

PMNotcopy: Brush's reverse color drawing of the color defined in the Color property;

PMMERGEPENNOT: Draw after the color defined in the Color property is drawn after the color of the screen color;

PMMASKNOTPEN: Draw after the brush is combined with the color defined in the Color property;

PMMERGENOTPEN: The brush is drawn after the reversal of the color of the color defined in the color attribute.

Brush properties, the brush properties have been described in detail in front, which can determine the fill mode of the graphics and fill colors.

Attribute ClipRect, used to determine the range of the drawing area. Any graphics exceeding this range will not be displayed.

66) Q: What kind of way we can use on Canvas objects?

A: There are some basic diagram methods: Canvas objects:

1. The first is the MoveTo method, MoveTo sets the current position of the pen to the point (x, y), the current location of the pen will be saved in the Penpos property, pay attention to, change the current location of the pen with the MoveTo method, not to modify the Penpos Attributes. The function form is MoveTo (X, Y).

2. The LINETO method is used to complete a straight line to point (x, y) from the current location, and move the position of the pen to this. The function form is LINETO (X, Y).

The starting point of the method MoveTo mobile line is generally first used in the drawing, and then the method LINETO is used.

3. Method Rectangle is used to draw a rectangle with the current draw brush on the canvas, where x1, y1 is the upper left corner coordinate of the rectangle, X2, Y2 is the lower right corner coordinate of the rectangle. Because the square is actually a special rectangle, you can use this method to draw a square. The function form is Rectangle (X1, Y1, X2, Y2).

4. Method Ellipset is used to draw an ellipse on a given rectangular boundary on the canvas, where x1, y1 is the upper left corner coordinate of the boundary rectangle, X2, Y2 is the lower right corner coordinate of the boundary rectangle. The so-called boundary rectangle is a circular or elliptical external rectangle. The function form is Ellipse (X1, Y1, X2, Y2).

5. Methods RoundRect is used to draw rounded rectangles: wherein X1, Y1, X2, Y2 are rounded corners and lower right corners of rounded rectangular virtual. X3, Y3 is the length of the rounded corners. The function form is RoundRect (X1, Y1, X2, Y2).

6. Method Polygon can draw polygons. The function is Polygon (TPoint P, int point_size).

Parameter P is an array of class TPoint, and each TPOINT object contains a point of X and Y coordinates. Points_size is used to indicate the size of the array. This is a solid polygon, and POLYLINE is a polygon, and the use is basically the same.

67) Q: Is it true that the text information is displayed in the display area, is we also implemented in DOS?

A: Printf is a console function that cannot be used in a window program, usually our TextOut output text, its declaration: void _fastcall textout (int X, int y, const aion text); where x, y is output string starting point The coordinates, Text is the text to be output. Of course, you have to use Lable is also possible J (to be continued)

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

New Post(0)