Results 1 to 11 of 11

Thread: [RESOLVED] [2005] After form has loaded event?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Resolved [RESOLVED] [2005] After form has loaded event?

    hello!

    i have created a small program with an update check feature. So that when a user clicks "check for update" a form is displayed that checks.. However, using the mybase.load event makes it check for the update before the form is displayed, meaning the user wont get feedback untill after the checking procedure is complete. How can i make the program launch this event automatically after the form has loaded?

    Cheers!

  2. #2
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [2005] After form has loaded event?

    Double click on the form (this will take you to the code executed when the form is loaded) and put the code there.
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Re: [2005] After form has loaded event?

    that is what I have done, but this results in what ive already mentioned.. This also results in long loading times when you open the form as it wont display before the actions are executed..

    but thanks anyways

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Re: [2005] After form has loaded event?

    This code did it..

    VB Code:
    1. Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] After form has loaded event?

    Quote Originally Posted by Untouchab1e
    This code did it..

    VB Code:
    1. Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    Be carefull with this event... It'll fire everytime the form is activated (exactly as the event name suggests)....

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Re: [RESOLVED] [2005] After form has loaded event?

    Yeh, i quickly experienced it.. What does work is this though

    VB Code:
    1. Me.Show()
    2.         Application.DoEvents()

  7. #7
    Hyperactive Member
    Join Date
    May 2005
    Posts
    334

    Re: [RESOLVED] [2005] After form has loaded event?

    If I understand you, you want the user to click an 'Update' button which launches a form on which the user clicks something else to actually do the update, right? If that's the case then I'd move the update from the Load event to the Click event.

    Alternatively, maybe you want the 2nd form more like a splash screen, where it simply appears while the update takes place in the background. I'm not sure exactly how to do that, but I'd probably look at starting a new thread for the update while continuing with the Load procedure (which would no longer contain the update) in the current thread. When the update is done it raises an event in the displayed form. Like I said, I'm not sure exactly how to do that, but that's the general procedure I'd try.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Re: [RESOLVED] [2005] After form has loaded event?

    The solution i posted above works perfectly for my situation. The user clicks a menu item "Check for update", then the a form shows, showing progress on the update-checking (establishing connection, downloading info.. etc)

    Cheers!

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] After form has loaded event?

    I do wonder sometimes whether anyone ever uses the help documentation that Microsoft provide with Visual Studio and probably spent millions of dollars to create. The Shown event was introduced in .NET 2.0 specifically because people often wanted to do something when the form first appears. As has been stated the Activated event is raised every time the form becomes active, so to use that you generally had to use a boolean flag to indicate whether this was the first event or not. If you use the Activated event and the user activates another application then goes back to your form the whole process will be executed a second time, which is definitely NOT what you want. This means that your solution does not work perfectly in situations that you have not tested. Use the right tool for the job, which can more often than not be found by a quick perusal of the relevant help topics.
    Attached Images Attached Images  
    Last edited by jmcilhinney; Feb 5th, 2007 at 06:45 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Addicted Member
    Join Date
    Dec 2006
    Location
    Georgia
    Posts
    170

    Re: [RESOLVED] [2005] After form has loaded event?

    Quote Originally Posted by jmcilhinney
    I do wonder sometimes whether anyone ever uses the help documentation that Microsoft provide with Visual Studio and probably spent millions of dollars to create.
    Not to hijack the thread, but quite honestly, I don't use it as much as some VB.NET gray-beards would think I should because it's, in my opinion, not very well written. It's almost as greek to me as a new programming language is, which is the exact oposite of what it's supposed to be. That said, if M$ spent millions of dollars to create it, I'd almost feel sorry they wasted their money.

    I digress.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] After form has loaded event?

    Quote Originally Posted by highflight1985
    Not to hijack the thread, but quite honestly, I don't use it as much as some VB.NET gray-beards would think I should because it's, in my opinion, not very well written. It's almost as greek to me as a new programming language is, which is the exact oposite of what it's supposed to be. That said, if M$ spent millions of dollars to create it, I'd almost feel sorry they wasted their money.

    I digress.
    I've learned the vast majority of what I know from MSDN and I don't speak Greek. I'm no genius so I I can do it then anyone can. Most people just don't use it properly. I often see posts where people say "I searched but couldn't find anything". The vast majority of times there is no searching required. In this case, you want to do something when somethiung happens in a form. "When something happens" immediately means an event, so you go straight to the event listing for the Fomr class, as my previously posted image shows. Reading down the list I think that the name and description of the Shown event pretty much match the circumstances of this current request. Clicking the name takes you to the topic for that event and it includes this:
    The Shown event is only raised the first time a form is displayed; subsequently minimizing, maximizing, restoring, hiding, showing, or invalidating and repainting will not raise this event.
    Now that exactly matches the current requirement so that's the question answered in less than two minutes.

    I'm better at using MSDN now than I was when I first started. To get the most out of it you need to practice. You won't always get what you need but you will more often than not. To just not bother is simply lazy in my opinion. I did it and it wasn't hard. Anyone who applies logic and perseverence can do it too. It's a great resource and it's made me the developer I am. It's money well spent.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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