See Also Example
Form, picture box.
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.
Sub Form_Paint ( )
Sub ctlname_Paint ([Index As Integer])
The argument Index uniquely identifies a control if it is in a control array.
A Paint procedure is useful if you have output from graphics methods With a Paint procedure, you can ensure that such output is repainted when necessary. in your code.
If the AutoRedraw The Paint event is also invoked when the Refresh method is used. property is True, repainting or redrawing is automatic so no Paint events are necessary.
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 Resize 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 event . 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.
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)