See Also Example
Clears graphics and text generated at run time from a form or picture.
Syntax
[object.]Cls
Remarks
The object can be a form or picture box control. If object is omitted, Cls clears text and graphics from the current form.
Cls clears text and graphics generated at run time Background bitmaps set using the Picture property and controls placed on the form at design time are not affected by Cls. Graphics and text placed on a form, image, or picture box control while AutoRedraw property is True are also not affected if AutoRedraw is set to False before Cls is executed. That is, some degree of permanence can be achieved by carefully manipulating the AutoRedraw property of a form, image, or picture box control.
After Cls is executed, the CurrentX and CurrentY properties of a form, image, or picture box control are reset to 0.
AutoRedraw Property
CurrentX Property
CurrentY Property
The example uses the Cls method to erase printed information on a form. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Msg ' Declare variable
AutoRedraw = -1 ' Turn on AutoRedraw.
ForeColor = QBColor(15) ' Set foreground to white.
BackColor = QBColor(1) ' Set background to blue.
FillStyle = 7 ' Set diagonal crosshatch.
Line (0, 0)-(ScaleWidth, ScaleHeight), , B ' Put box on form.
Msg = "This is information printed on the form background."
CurrentX = ScaleWidth / 2 - TextWidth(Msg) / 2 ' Set X position.
CurrentY = 2 * TextHeight(Msg) ' Set Y position.
Print Msg ' Print message to form.
Msg = "Choose OK to clear the information and background "
Msg = Msg & "pattern just displayed on the form."
MsgBox Msg ' Display message.
Cls ' Clear form background.
End Sub