AutoRedraw Property

See Also7BXHIC                 Example8INK0X9>Low

Applies To

Form14TJ2LN, picture box31MYIWX.


Determines the output from a graphics methodAY3LGR to a persistent bitmap41CTZFK.


[form.][picturebox.]AutoRedraw[ = { True|False}]


The AutoRedraw property settings are:

Setting           Description


True               Enables automatic repainting of a form or picture box. Graphics and print output are written to the screen and to an image stored in memory. The object does not receive Paint25UTDKO events; it is repainted when necessary, using the memory image.

False              (Default) Disables automatic repainting of an object and writes graphics or print output only to the screen. Visual Basic invokes the object's Paint event when necessary to repaint the object.



This property is central to working with the graphics methodsCircle38E9WK, ClsLANCLS, LineGU01B0, Point3QAMBS, Print9V51E5, and PSet103J0PY.  Setting AutoRedraw to True automatically redraws the output from these methods in a form or picture box when, for example, the object is resized or redisplayed after being hidden by another window.

You can reset AutoRedraw in code at run time to alternate between drawing persistent graphics (such as a background or grid) and temporary graphics. If you disable AutoRedraw, previous output becomes part of the background screen. When AutoRedraw is set to False, background graphics are not deleted if you clear the drawing area with the Cls method. Setting AutoRedraw back to True and then using Cls clears the background graphics.


Note   If you set the BackColor1W9T6JQ property, all graphics and print output, including the persistent bitmap, are erased.  In general, all graphics should be in a Paint event unless AutoRedraw is set to True.

To retrieve the persistent bitmap created when AutoRedraw is set to True, use the Image6AEZWAR property.  To pass the persistent bitmap to a Windows APIDEFAPI when AutoRedraw is set to True, use the object's hDCZVPW3G property.

When you minimize a form whose AutoRedraw property is set to False, the ScaleHeight3J8U7ZN and ScaleWidth3J8U7ZN properties are set to icon size.  When AutoRedraw is set to True, ScaleHeight and ScaleWidth remain the size of the restored window.


Data Type

IntegerDOKXHY (Boolean)

See Also


Circle Method38E9WK

Cls MethodLANCLS

Image Property6AEZWAR

Line MethodGU01B0

Paint Event25UTDKO

Point Method3QAMBS

Print Method9V51E5

PSet Method103J0PY

ScaleHeight, ScaleWidth Properties3J8U7ZN


Programmer's Guide:

Chapter 15, "Creating Graphics for Applications"

AutoRedraw Property Example

The example alternately displays two drawings on a picture box control: a persistent filled circle and temporary vertical lines.  Click the picture box to draw or redraw the lines.  Resizing the form requires the temporary drawing to be redrawn.  To try this example, paste the code into the Declarations section of a form that has a picture box control named Picture1.  Press F5 to run the program and click the picture each time you resize the form.

Sub Form_Load ()
  Picture1.ScaleHeight = 100            ' Set scale to 100.
  Picture1.ScaleWidth = 100
  Picture1.AutoRedraw = True            ' Turn on AutoRedraw.
  Picture1.ForeColor = 0                ' Set ForeColor.
  Picture1.FillColor = QBColor(9)       ' Set FillColor.
  Picture1.FillStyle = 0                ' Set FillStyle.
  Picture1.Circle (50, 50), 30          ' Draw a circle.
  Picture1.AutoRedraw = False           ' Turn off AutoRedraw.
End Sub

Sub Picture1_Click ()
  Dim I                                    ' Declare variable.
  Picture1.ForeColor = Rgb(Rnd * 255, 0, 0) ' Select random color.
  For I = 5 To 95 Step 10                  ' Draw lines.
    Picture1.Line (I, 0)-(I, 100)
End Sub