How to Place Animated Graphics on a Minimized Form in VB

Last reviewed: June 21, 1995
Article ID: Q79601
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SUMMARY

You can place animated graphics onto a minimized form in Visual Basic. Normally, when a form is minimized, the form is replaced with an icon that had been previously set using the Icon property of that form. This icon is an actual bitmap that cannot be manipulated. Using the method below, the icon can be replaced with a set of graphics methods that will draw to the minimized form.

MORE INFORMATION

To place animated graphics onto a minimized form, you must use a timer event. This will allow the program to continue its animation when the form is minimized. A minimized form is just like a non-minimized form, except its size is decreased and certain rules apply. The following guidelines should be followed when creating animated graphics on a form:

  • The AutoRedraw property must be set to 0 (False).
  • The user must place routines in the Paint event procedure to handle cases when the Paint event occurs in the maximized form. In the minimized form, a Paint event never occurs, and you must depend upon the timer event to refresh the icon representing the minimized form.
  • The user must handle the painting of the background because a minimized form has no background, only foreground.
  • Adjust your animation to the size of the minimized form by using either the Scale method or the ScaleWidth and ScaleHeight property.

The following example creates an animated icon that displays random circles every 500 milliseconds:

  1. From the File menu, choose New Project.

  2. Remove the icon from the Icon property. (You can do this by selecting the Icon property and pressing the DELETE key.)

  3. Place a new timer control on the form.

  4. Change the timer interval to 500.

  5. Type the following code into the new timer event:

Static prevx!, prevy!
If windowstate = 1 Then           'Checks to see if form is
                                  'minimized.
    form1.Scale (0, 0)-(100, 100) 'Sets the max height and
                                  'width of the form.
    fillcolor = QBColor(0)
    Circle (prevx!, prevy!), scalewidth / 10, QBColor(0)
    fillstyle = 0
    fillcolor = QBColor(1)
    prevx! = Int(Rnd(1) * scalewidth) + 1
    prevy! = Int(Rnd(1) * scaleheight) + 1
    Circle (prevx!, prevy!), scalewidth / 10, QBColor(1)
End If

  1. From the Run menu, choose Start.

  2. Minimize the form by choosing Minimize from the control box menu, or click the minimize arrow (the minimize arrow is the down arrow) on the form.


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.