Link to home
Start Free TrialLog in
Avatar of ElrondCT
ElrondCTFlag for United States of America

asked on

Display messagebox immediately after form load

In VB .NET 2003, I want to display a messagebox immediately after the main form of the application has loaded (so that the form is visible behind the messagebox). If I put the messagebox code inside the Load event handler, the messagebox displays without the application form behind, but I can't figure out a way to delay its display.
Avatar of TSmooth
TSmooth

Put your MessageBox code in the Form's "Shown" event handler. This will work well as long as you aren't programatically hiding and reshowing your form. If you are programatically hiding and showing the form and only want it to come up when the program is first run, use some variable that is toggled when the program is first run and the message box is shown.
Avatar of ElrondCT

ASKER

I don't see a Shown event for the form. It looks like that's in VS 2005 and not 2003, which is what I'm using.

I won't be hiding the form; it'll be visible as long as the program is running.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or use form Activated, with a flag

    Private StartUpShown As Boolean = False 'at form level

    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        If StartUpShown Then Exit Sub
        MessageBox.Show("Start up message")
        StartUpShown = True
    End Sub

Roger
ACK!!!! The timer idea seemed like a good one, so I put that on my form. As soon as I tried to switch from the designer to the code, VB went crazy, running up over a thousand build errors, all of the form:

Code generation for property 'Name' [or various other properties] failed.  Error was: 'There was an error loading app.config. Since the document being loaded uses Dynamic Properties, the config file must be valid.

I've never seen that before (and there's almost nothing that matches it on the web). I put two config files in the directory, one named "app.config" and the other "EZ13.config" (EZ13.exe being the name of the application). At that point, I didn't see any errors flagged in the code, so I tried to run the program. It failed, because the combo boxes didn't have any elements in them. When I went back to the designer and displayed the form to see what had happened to the combo boxes, virtually every control disappeared from the form.

Well, that was pretty lousy; I should have known better than to allow the autosave to save the changes to the source code while I was looking to see what had happened. But no problem, I figured; I'm subscribed to an online backup system, which saves my files every night. Just restore, and I'm on my way.

THE BACKUP WASN'T SAVING MY SOURCE CODE!!! The .vb files are listed in the history log, but what's on the server is over a month old and hacked up at that. It looks like I'm seriously hosed. I've got a message in to the backup company, but I doubt there's anything they can do. I checked, and at least some, if not all, of my other .vb files haven't been properly backed up in the last month, though they all appear in the logs as backed up. (They are now backed up in a zip archive, stored on my company's FTP server. Fool me once...) Only one of the files got trashed by this, but of course it's the main form, some 350 KB in size.

Moral of the story: For really important stuff, don't rely on a single form of backup. I have no idea how long it's going to take me to recover from this (and I was planning on sending out tomorrow the announcement that the software was ready to purchase).
Ouch.  You have my sympathy

Roger
Well, it didn't take as long as I feared to rebuild. Fortunately, I haven't changed the design of the controls much in the last month, and even though the controls got wiped off the form, none of their event handlers were deleted. The last valid backup was from about a month ago, so I used that to repopulate the form, then copied all the event handlers from the file that had remained after the neutron bomb struck, and with just a couple more hours of work, everything seems to be back in good shape. But I'm doing a lot more careful backups now.

I put a .config file in the folder, and this time when I put a Timer on the form, had no problems.
Well I am glad that it all worked out for you in the end although it would have been nice if the company you used for backups would have done there jobs and had saved you all this work.
Yes, I'm working with them to track down what's happening. Fortunately (for debugging purposes), it's a reproducible error, so I'm hoping we'll get it figured out fairly quickly. Though I'm not sure I'll stick with them at this point...