What's the difference between the Form_Activate event & Form_Paint event?
Printable View
What's the difference between the Form_Activate event & Form_Paint event?
Just put this code in your form, run the application, check the Immediate window, and see for yourself:
Code:Private Sub Form_Activate()
Debug.Print Timer, "Form_Activate"
End Sub
Private Sub Form_Paint()
Debug.Print Timer, "Form_Paint"
End Sub
Form_Paint event occurs when form (or part of it) gets refreshed (or repainted). If AutoRedraw is set to True then there is no need to use Paint event - it's done automaticallyand event is not trigerred.
You will see how it works if you run this sample - make sure AutoRedraw is set to False:
Activate event I think is self explanatory. :)Code:Private Sub Form_Click()
Me.Refresh
End Sub
Private Sub Form_Paint()
Debug.Print "Form_Paint"
End Sub
Just in case it's not, the Activate event occurs whenever a form becomes the active form.
Suppose I run an app with only 1 Form from the VB IDE; the Form becomes the active Form & hence the Form_Activate event fires. Next I switch to some other open app & again switch back to the VB app. Now also the Form becomes the active Form but the Form_Activate event doesn't fire. So Form_Activate fires only when a Form becomes the active Form within the app, isn't it?Quote:
Just in case it's not, the Activate event occurs whenever a form becomes the active form.
For e.g. an app has 2 Forms - Form1 & Form2. Clicking a menu in Form1 (which is the start-up Form) invokes Form2. Now when the app is run, Form1 becomes the active Form & hence Form1's Activate event will fire. Next I click the menu to invoke Form2. Now Form2 is the active Form; hence Form2's Activate event will fire. Next I unload Form2. This again makes Form1 the active Form & hence Form1's Activate event fires again.
All true.