开发者

Add a spinning wheel while application is searching database

开发者 https://www.devze.com 2023-01-27 21:19 出处:网络
I have an application that searches in a database for some information. Since the database is quite big, it sometimes takes a lot of time before the application returns the results to the interface.

I have an application that searches in a database for some information.

Since the database is quite big, it sometimes takes a lot of time before the application returns the results to the interface.

I want to add some sort of spinning wheel to inform the user that the application is still searching the dat开发者_开发百科abase and did not freeze. Once the results are returned, the wheel should disappear.

Any idea how to do this or is there a good tutorial explaining how to do this?


Have you considered changing the mouse pointer to the hourglass as this would be extremely simple to implement:

Me.Cursor = Cursors.WaitCursor 

...Do your DB calls here...

Me.Cursor = Cursors.Default

However, I would agree that display a 'spinning wheel' is probably a little more user friendly and definately a lot more obvious. So, first get hold of an animated gif that suits your needs. Then create a form that has a picture box containing the image.

Once you have that you can show the form to the user and in the background do the DB work, once this has completed close the form.

Another alternative would be to use a rolling progress bar instead, so when it reaches 100% it cycles around again and keeps going until you close it.

EDIT:

One thing that I forgot to mention is that you will have to handle exception conditions. Lets say you set the cursor to wait, then an error occurs. The exception may bypass the code that resets everything. This leaves the user with a changed cursor and no means of changing it.

When I have done this kind of thing I have typically created a disposable WaitCursor class and then used something like this:

Using myWaitCursor As WaitCursor = New WaitCursor
...do something...
End Using

In the Dispose of the WaitCursor class you set the cursor back to default. The same would apply if you went down the route of using a form with an image or progress bar.


Find an animated gif of such a spinner, like this one. Put it in a PictureBox, set its Visible property to True when you start the job. Beware that you'll have to run the query in a worker thread to keep the animation alive and the user interface responsive. The BackgroundWorker class is good for that.


You could use the Environments Default wait cursor, which for Vista/7 is a circle with the outside spinning, or the XP tumbling hourglass.

You could launch your DB access on a BackgroundWorker and show an animated control such as a Marquee progress bar, or you could show a custom animation to show Busy status.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号