Paint Event; PaintLeft, PaintTop, PaintWidth, and PaintHeight Properties

Purpose

The Paint event occurs when a Form is first displayed or when part or all of a Form is exposed after being moved or enlarged, or after a window that was covering the object has been moved.

Syntax

Sub Form_Paint( [index%] )

x! = Form.PaintLeft
x! = Form.PaintTop
x! = Form.PaintWidth
x! = Form.PaintHeight

index%:iexp, Form number
x!Single exp

Description

A Paint event procedure is useful if you have output from graphics methods in your code. With a Paint procedure, you can ensure that such output is repainted when necessary. The Paint event is also invoked when the AutoRedraw property is set to True.

The Paint event is invoked when part or all of the client area has been invalidated and/or the Refresh method is used.

The PaintLeft, PaintTop, PaintWidth, and PaintHeight properties specify the invalidated area, the area that needs updated. These properties are only valid inside the Paint event.

Example

OpenW 1, 10, 10, 300, 300

Ocx CheckBox chk = "Invalidate area 10,10 to 110,110", 10, 10, 180, 14

Do

Sleep

Until Win_1 Is Nothing

 

Sub chk_Click

If chk.Value = 1

Win_1.Invalidate 10, 10, 100, 100

Else

Win_1.InvalidateAll

EndIf

EndSub

 

Sub Win_1_Paint

Print AT(1, 4); "PaintLeft "; Me.PaintLeft; Space(10)

Print AT(1, 5); "PaintTop "; Me.PaintTop; Space(10)

Print AT(1, 6); "PaintWidth "; Me.PaintWidth; Space(10)

Print AT(1, 7); "PaintHeight "; Me.PaintHeight; Space(10)

EndSub

 

Sub Win_1_ReSize

// Resizing the Window invokes InvalidateAll

chk.Value = 0

EndSub

Resize the window and watch the changes in the Paint area dimensions.

Note that when you Invalidate the area 10, 10 to 110, 110 then PaintTop actually reads 24 and PaintHeight 86; this is due to the position of the checkbox area which is not included in the Invalidate statement.

Remarks

A ClearW command is not allowed in a Paint event, because it generates a WM_PAINT message.

See Also

Form

{Created by Sjouke Hamstra; Last updated: 21/10/2014 by James Gaite}