Results 1 to 6 of 6

Thread: Difference Between Activate & Paint

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Question Difference Between Activate & Paint

    What's the difference between the Form_Activate event & Form_Paint event?


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Difference Between Activate & Paint

    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

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Difference Between Activate & Paint

    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:
    Code:
    Private Sub Form_Click()
        Me.Refresh
    End Sub
    
    Private Sub Form_Paint()
        Debug.Print "Form_Paint"
    End Sub
    Activate event I think is self explanatory.

  4. #4

  5. #5

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Difference Between Activate & Paint

    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?

    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.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  6. #6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width