See Also Example
Applies To
Form, picture box
Description
Determines the output from a graphics method
Usage
[form.][picturebox.]AutoRedraw[ = { True|False}]
Setting
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 Paint
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.
Remarks
This property is central to working with the graphics methodsCircle 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 BackColor 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 Image To pass the persistent bitmap to a Windows API when AutoRedraw is set to True, use the object's hDC property.
When you minimize a form whose AutoRedraw property is set to False, the ScaleHeight When AutoRedraw is set to True, ScaleHeight and ScaleWidth remain the size of the restored window.
Data Type
Integer (Boolean)
Help:
Circle Method
Cls Method
Image Property
Line Method
Paint Event
Point Method
Print Method
PSet Method
ScaleHeight, ScaleWidth Properties
Programmer's Guide:
Chapter 15, "Creating Graphics for Applications"
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)
Next
End Sub