C# progress bar control is hard to use? - c#

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.

Related

Animated Busy Indicator in Compact Framework 2.0

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.

Simple multi-threading issue

I have a class called Movement which moves a picture box (guy on the left) on my form to a random position when it's Lead method gets executed. I also have a method which moves another picture box (dark guy on the right) called SetMrShadowToMove. These two picture boxes are suppose to move at the same time and arrive at the random point (one point for both picture boxes) at the same time.
For now, these methods use a timer to move the picture boxes, but my main intention was to have a loop which runs until the picture box's coordinates meet the random point picked while using Thread.Sleep to delay the process and make an animation of it.
To do that, I need to run both methods on different threads, so my UI thread doesn't get frozen and these methods would run at the same time.
My problem is that I don't know how to run these methods on different threads, and also don't know how to access the picture boxes on the other threads (it seems that this has something to do with invoking and stuff!).
What is the best way to solve this problem?
The best way (in my opinion) is by using a background worker.
those things can do there calculations in the background. If you you want to update the interface after that you can use there report progress event to invoke your main (interface) thread and redraw the screen. You can also the work complete even if you want to have a event of the background worker as a final even (for example if mister shadow is 'destroyed' or something).
I don't know your code of mister shadow so I don't have any direct example code for you. But a full example about how to use a background worker can be found on msdn here. I hope this will help you.

C# WinForms label will display, but not show text

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?

Oscillating horizontal green glow whilst something is loading c#

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.

Loading icon / progress bar

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

Categories

Resources