Icon Property Example

This example creates a blank icon for a form and draws colored dots on the icon as long as the form is minimized. To try this example, paste the code into the Declarations section of a form, and then press F5 and minimize the form.

Note   This example works only with Windows NT 3.5x.

Private Sub Form_Resize ()
   Dim X, Y   ' Declare variables.
   If Form1.WindowState = vbMinimized Then
      Form1.Icon = LoadPicture()   ' Load a blank icon.
      Do While Form1.WindowState = vbMinimized   
  ' While form is minimized,
         Form1.DrawWidth = 10   ' set size of dot.
         ' Choose random color for dot.
         Form1.ForeColor = QBColor(Int(Rnd * 15))
         ' Set random location on icon.
         X = Form1.Width * Rnd
         Y = Form1.Height * Rnd
         PSet (X, Y)   ' Draw dot on icon.
         DoEvents   ' Allow other events.
      Loop
   End If
End Sub

This is the same example, except that it uses the LoadPicture method to set the Icon property. This example works with all versions of Windows:

Private Sub Form_Resize ()
   Dim X, Y   ' Declare variables.
   If Form1.WindowState = vbMinimized Then
      Form1.Icon = LoadPicture("c:\myicon.ico")
  ' An icon named "myicon.ico" must be in the
  ' c:\ directory for this example to work
  ' correctly.
   End If
End Sub