Paint Event

See AlsoPI641O              Example3ZYYA4C>Low

Applies To

Form14TJ2LN, picture box31MYIWX.

Description

Occurs when part or all of a form or picturebox is exposed after it has been moved or enlarged, or after a window that was covering the object has been moved.

Syntax

Sub Form_Paint ( )

Sub ctlname_Paint ([Index As Integer])

Remarks

The argument Index uniquely identifies a control if it is in a control array8G7Y0UU.

A Paint procedure is useful if you have output from graphics methodsAY3LGR in your code.  With a Paint procedure, you can ensure that such output is repainted when necessary.

If the AutoRedraw1UY7ZM3 property is True, repainting or redrawing is automatic so no Paint events are necessary.  The Paint event is also invoked when the Refresh3SMNZGP method is used.

If ClipControls2102ZSX is False, graphics methods in the Paint event procedure affect only newly exposed areas of the form; otherwise, the graphics methods repaint all areas of the form not covered by controls (except image, label, line, and shape controls).

Using a Refresh method in a Resize2WM7WLP event procedure forces repainting of the entire object every time a user resizes the form.

 

Note   Using a Paint event procedure for certain tasks can cause a cascading event3N94RC2.  In general, avoid using a Paint procedure for the following:

         Moving or sizing a form or control.

         Changing any variables that affect size or visual appearance such as setting an object's BackColor property.

         Invoking a Refresh method.

 

A Resize event procedure may be more appropriate for some of these tasks.

 

 


See Also

Help:

AutoRedraw Property1UY7ZM3

Circle Method38E9WK

ClipControls Property2102ZSX

Line MethodGU01B0

Print Method9V51E5

PSet Method103J0PY

Refresh Method3SMNZGP

Resize Event2WM7WLP

 

Programmer's Guide:

Chapter 15, "Creating Graphics for Applications"


Paint Event Example

The example draws a diamond that intersects the center point of each side of a form and adjusts automatically as the form is resized.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and resize the form.

Sub Form_Paint ()

   Dim HalfX, HalfY                      ' Declare variables.

   HalfX = ScaleLeft + ScaleWidth / 2    ' Set to half of width.

   HalfY = ScaleTop + ScaleHeight / 2    ' Set to half of height.

   ' Draw a diamond.

   Line (ScaleLeft, HalfY) - (HalfX, ScaleTop)

   Line -(ScaleWidth + ScaleLeft, HalfY)

   Line -(HalfX, ScaleHeight + ScaleTop)

   Line -(ScaleLeft, HalfY)

End Sub

 

Sub Form_Resize

   Refresh

End Sub