I am launching a search just after starting a form (initial parameters and so on).
My problem is that the form is not shown open until the search is finished.
I would like to open the form window and show parameters and so before launching the search, just to show the user that something is going on.
I have tried with a button and generating the button click event after opening the form, but it does not work in the way that I expected (just the same result).
The refresh (this.Refresh();) does not work either.
Any idea about how to program that?
Thank you in advance.
There are a couple of ways to do this: clearly the nicest from the user perspective is to do it the "proper" way - by moving the time consuming operation into a BackgroundWorker thread and showing the progress.
However, you can show that something has happened by doing it in the Form.Shown event rather than in the Load event or in the constructor. Probably, it won't be very good, unless the search takes very little time, and the controls on the form will not be painted until the shown event (and all other non-background events) have finished processing - Paint is a low priority operation and doesn't happen until there is nothing else going on.
The other method is to use a timer - start it with a half second delay, and stop it them do the long operation in the event handler.
Both of these will do something, but they are quite nasty from a user POV because they will lock up the UI thread until they finish. A BackgroundWorker is a much better solution, if a small amount of extra work for you.
Leave the initializer alone as they are; so that the basic form initialization will take place first.
Create a timer (set the timer to have enough time to load your form) and start timer in "Form_Load" event.
When the timer ticks on the first time call your search function and disable the timer.
If you want to be more productive, you can make use of the timer to show the elapsed time to the user.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)