Programming C++Builder Basic Knowledge for Graphics Programming in CBuilder or Delphi
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/ on line 149

First step to learn graphics programs--How to refresh the screen?

At certain times, the operating system determines that objects onscreen need to refresh their appearance, so it generates WM_PAINT messages on Windows, which the VCL routes to OnPaint events. (If you are using CLX for cross-platform development, a paint event is generated, which CLX routes to OnPaint events.) If you have written an OnPaint event handler for that object, it is called when you use the Refresh method.

The default name generated for the OnPaint event handler in a form is FormPaint. You may want to use the Refresh method at times to refresh a component or form. For example, you might call Refresh in the form's OnResize event handler to redisplay any graphics or if using the VCL, you want to paint a background on a form.

While some operating systems automatically handle the redrawing of the client area of a window that has been invalidated, Windows does not. In the Windows operating system anything drawn on the screen is permanent. When a form or control is temporarily obscured, for example during window dragging, the form or control must repaint the obscured area when it is re-exposed. For more information about the WM_PAINT message, see the Windows online Help.

If you use the TImage control to display a graphical image on a form, the painting and refreshing of the graphic contained in the TImage is handled automatically. The Picture property specifies the actual bitmap, drawing, or other graphic object that TImage displays. You can also set the Proportional property to ensure that the image can be fully displayed in the image control without any distortion. Drawing on a TImage creates a persistent image.

Consequently, you do not need to do anything to redraw the contained image. In contrast, TPaintBox's canvas maps directly onto the screen device (VCL) or the painter (CLX), so that anything drawn to the PaintBox's canvas is transitory. This is true of nearly all controls, including the form itself. Therefore, if you draw or paint on a TPaintBox in its constructor, you will need to add that code to your OnPaint event handler in order for the image to be repainted each time the client area is invalidated.

How many types of graphic objects can I use in C++Builder or Delphi?

The VCL/CLX provides the following graphic objects. These objects have methods to draw on the canvas, which are described in Using Canvas methods to draw graphic objects and to load and save to graphics files, as described in Loading and saving graphics files.

Object Description
Picture Used to hold any graphic image. To add additional graphic file formats, use the Picture Register method. Use this to handle arbitrary files such as displaying images in an image control.
Bitmap A powerful graphics object used to create, manipulate (scale, scroll, rotate, and paint), and store images as files on a disk. Creating copies of a bitmap is fast since the handle is copied, not the image.
Clipboard Represents the container for any text or graphics that are cut, copied, or pasted from or to an application. With the clipboard, you can get and retrieve data according to the appropriate format; handle reference counting, and opening and closing the clipboard; manage and manipulate formats for objects in the clipboard.
Icon Represents the value loaded from an icon file (::ICO file). 
Metafile (VCL only)Drawing (CLX only) Contains a file that records the operations required to construct an image, rather than contain the actual bitmap pixels of the image. Metafiles or drawings are extremely scalable without the loss of image detail and often require much less memory than bitmaps, particularly for high-resolution devices, such as printers. However, metafiles and drawings do not display as fast as bitmaps. Use a metafile or drawing when versatility or precision is more important than performance.

Add comment

Security code

Programming - C++Builder