what control can i use to place in my programme so that i can have a loading bar. For example
ProgressBar pb = new ProgressBar();
pb.start();
connectToDatabase();
pb.stop();
Is this possible in c#?
Thanks
Sure. There's a ProgressBar control in the Windows Forms library. Set its Style to Marquee and you should get a scrolling on/off pattern that indicates progress is being made.
A ProgressBar requires your code to periodically update the progress as you work through the task. Also, the progress only has meaning when you can roughly calculate what percent you have completed.
If you just want something moving to show that the program is busy, you can set the progress bar Style property to ProgressBarStyle.Marquee. This style is used to indicate something is happening without reporting the percent the task is complete.
Is there not a simple control called progressbar? Or are you asking something more complex that I'm missing?
Heres a knowledgebase article about created a smooth progressbar
Link to Article.
And heres a tutorial
Related
So I'm pulling some stuff from a database via a different thread, and want the form to remain usable while doing so, and also want to show the user a progress indicator until the DB code finishes.
In 'normal' winforms I'd use a ProgressBar with the ProgressBarStyle set to Continuous, but CF doesn't have that. Neither does it seem to support animated GIFs in a PictureBox (which would have been an easy way).
So what are my options for doing something like this?
EDIT: Don't want to use an hourglass mouse cursor because that implies to the user that the UI is busy (it's not).
Thanks
You could look for a 3rd party progress bar control that supports the Continuous progress bar style, or a control that supports animated gifs - you're not the first running into this limitation, but I'm not sure if there are any good ones out there.
Rolling your own "continuous" progress bar UserControl shouldn't be very hard, you get a decent result with just a timer to call Invalidate, and using Graphics.FillRectangle in the Paint event.
An alternative to an animated gif control could be to create a "film strip" UserControl, where you provide an image (non-gif) that contains all "frames" of the gif layed out horizontally or vertically. Again you'd need a timer to call Invalidate and increase the frame number, and Graphics.DrawImage has an overload to specify which portion of the film strip image is drawn.
Instead of the timer you could use #josef's comment to increment the "current frame" whenever the worker thread has finished a portion of the work. The animated gif's "movement" would then actually show the user that work is being done.
I'm designing a GUI and I have a label which I use effectively as a 'please wait' message after I invoke an action that tends to take a while. The label's text is static, I have set it in the properties in VS2010 for the label control.
When I hit that action on the form, I .Show() the control which is normally hidden until the time consuming process completes, then .Hide() it. When it hits the .Show() the label pops up (I know this because I have the BorderStyle set to Fixed3D so I see the border of the label show up) but there is no text in it whatsoever. I have tried setting the label to autosize and not to no avail, my text is set to black on gray, so no invisible ink, everything is visible, font is set. Code executes as I want it to throughout, theres just no text in the label. I'm at a loss.
Any ideas?
If the time consuming process is occurring on the same thread, then it could be a refresh/redraw issue (where the processor is too busy to handle UI requests). Try either refreshing the window before starting the long running process or, more appropriately, putting the time consuming process in a BackgroundWorker.
If the time-consuming process is not executing in a background thread, then your UI isn't updating because no message processing is taking place. Controls redraw themselves in WM_Paint messages.
Try calling Refresh on the control or on its window-handle parent (the form) after changing its state, before diving into the long process.
Or, move the long-running process into a background thread (see .NET 4.0 Task) to free up the UI thread.
Maybe I'm missing something, but why don't you just set label.Visible?
I was using a program made in C# and came across these progress bars, one of which is blue.
Here's a picture of the progress bars in question:
The forecolor property obviously doesn't do anything, so does anyone know how to do this?
Thanks
If its a winform application then do the following step
In Program.cs comment out the line
Application.EnableVisualStyles();
In code behind:
ProgressBar1.ForeColor = Color.Blue;
ProgressBar1.Style = ProgressBarStyle.Continuous;
Disabling Visual styles as Habib suggested will work, But if you application relies on visual styles to look nicer, You will have to use a custom progress bar.
Color Progress Bar - CodeProdject
TerrariViewer uses Wpf as I understand, and if your willing to use that, this is a possibility
Progressbar foreground color
When loading something such as a software update in Windows 7 there is often an oscillating green glow effect in a horizontal bar. Is this a standard control that can be utilized in C#? If not, how can it be incorporated into a C# app.?
This control is called ProgressBar.
If you are using WPF the property IsIndeterminate has to be set to true to have a "running green glow".
You can implemented this using BackgroundWorker to update a progress bar ("the green glowing horizontal bar), and the same time keep the application main thread responsive. See this SO post, or google around BackgroundWorker + Progress bar.
I don't know how to start and stop the Marquee. Could you give some example about Marquee usage;And i don't want to set the initial status of progress bar to be continous or blocks becuase there will be flash when i change the style of progress bar to be Marquee..
thanks in advance
Hey, if you have synchronous blocking job on main/GUI thread you won't escape nasty things with Marque.
Marque WON'T create separate thread for its animation!
You have to DoEvents or anything similar to that for example run the dialog with the Marque on separate thread.