views:

1598

answers:

6

I don't know how long an action could take and I want to display a progress bar to the user in a dialog box. I've tried using System.Windows.Forms.ProgressBar but it doesn't seem to support it.

An example of what I'd want is the progress bar that windows shows you when it's looking for new drivers on the internet. It's just got three or four 'bars' going back and forth marquee style on the progress bar.

How can I do this?

+4  A: 

Just use an animated gif :)

You can make your own here: http://www.ajaxload.info/

Chris Lawlor
+12  A: 

System.Windows.Forms.ProgressBar has a property called Style. Setting Style to Marquee will achieve the effect your looking for.

EDIT: Divo points out the Marquee Style is only available on

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003

The comments provide even more information indicating that this appears to work everywhere as long as you're using .NET 2.0 or higher.

Mykroft
Seems Microsoft can't let go of "marquee" entirely. :-D
Tomalak
Make that "Windows XP or higher". I've just tested on Windows Vista and Windows 7 Beta (both 64 bit, though) and it worked.
Joey
Note: This is a .NET 2.0+ feature. .NET 1.1 did not expose the style property.
codeelegance
As the question is tagged .net3.5 I think it's safe to assume the asking person won't try to use it in .NET 1.1
Joey
+5  A: 

Have you tried setting the Style property of the System.Windows.Forms.ProgressBar to Marquee?

However, surprisingly, this property is only available on the following platforms (according to MSDN):

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003

Might be that the documentation has not been updated to Vista though. Anyone knows about a limitation on Vista?

EDIT: As posted in another comment the documentation seems to be wrong with respect to the supported platforms. Should be working on Vista as well as Windows 7.

0xA3
A: 

There might be a better way, but one way is just to set Value back to 0 when it reaches the end (assuming your task isn't complete)

Davy8
I feel physical pain every time I see a program doing that. From a usability POV, this is among the worst things a lazy programmer can do. It is uninformative, wrong, distracting, annoying and diminishing user trust in the "progress bar"-metaphor as a whole. Even no progress bar at all is better.
Tomalak
Agreed. Probably the best solution for a long-running process for which no progress information can ever be obtained (the question was a bit unclear), would be no progress bar at all ... but hey, he asked how to get an indeterminate one :)
Joey
Seems like I misread the desired effect. That was the only infinite progress bar that I could remember off the top of my head.
Davy8
No progress bar is definitely worse if it's going to be long (say more than 10-30 seconds depending on the patience of the person and how slow they expect their computer to be. I usually consider killing a process after 30 seconds of no progress indication
Davy8
@Davy8: I've always liked the idea of a logo (i.e. an analogue clock abstraction) that rotates a bit when something happens ("file copied" event or such). If many things happen it rotates fast, if few things happen, it rotates slowly. If the process is dead, it does not rotate at all.
Tomalak
Also "no progress bar"does not equal "no indication that the process id doing something". You can still switch the cursor to a busy one, tell the user what you do, etc. But a progress bar is not the ideal idiom if you have a process where you can't estimate completion or progress.
Joey
A: 

I have build an application that asynchronous go to a web page and grab some data. The problem is that while the application is doing this, the user doesn't know what's happening. It seems that the application is doing nothing when it's actually doing. I just want to show the user this.

Felipe Almeida
A: 

I found Chris Lawl's solution the best, very good and clean solution just include a gif http://www.ajaxload.info/ and no mess creating never ending progress bar.

Adeel