1. Computing & Technology

Discuss in my forum

Chapter 16 - Adding Graphics and Animation Effects

By , About.com Guide

5 of 5

The Code and Result of Monitoring the Paint Event
Paint

~~~~~~~~~~~~~~~~~~~~~~~~~
Dim paintcount As Integer = 0
Private Sub Form1_Paint( _
  ByVal sender As Object, _
  ByVal e As System.Windows.Forms.PaintEventArgs) _
  Handles MyBase.Paint
  paintcount += 1
  Debug.Write("Paint Event executed " _
    & CStr(paintcount) & vbCrLf)
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~

You will then see just when and how often the Paint event is called automatically as you resize, move, or minimize the window. In the My Moving Icon example in the book, because the timer is enabled from the first button click and never disabled, the form is repainted every 75 milliseconds no matter what else the program is doing. (This is why the example doesn't use a Paint event.)

Considerations like these can seriously impact the performance of your program ... or explain why it's not working the way you expect!

©2012 About.com. All rights reserved.

A part of The New York Times Company.