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 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 applications), 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.
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|