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.
Related
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´m using WinForms. I want to make a little class, which modifys controls to show it´s working.
I want to draw an overlay over for example a button. It should be a half-transparent gray.
After that i want to draw a ProgressBar on over it (in the center). Similar to This, except using a progress bar.
How can i realize this? I don´t want to set the position of the progressbar, just drawing it on the other one.
How could i do this?
Thanks :)
I have done something similar before.
You need to use Button.DrawToBitmap(Bitmap, Rectangle) to get the image of the button. Then make the Bitmap grayscale (there are multiple algorithms available for this; I have used the last one successfully although probably not originally from this site).
Now, I did this with an entire form instead of a button, but I disabled the form, and then covered the entire form with an image of itself, altered and then covered it with the progress bar (itself in a panel with other controls).
You could just as easily disable the button, cover it with a panel containing the image and the progress bar on top of it.
I have written some code to change a button's background image on mouse-hover, however when the image is changes it seems that it is a bit slow to complete.
That is, the process of setting the new picture as its background image is slow. By slow I mean a few milliseconds, but still enough to be seen!
Is there anything I can do about this, to speed up this process?
let use mouse move (the mouse overed control)
I need to "animate" an arrow. It can go in any direction (up, down, left, right and diagonals) and the arrowhead will be at the end. It needs to appear as if it is growing from orgin to the end.
To make matters more complicated it has to be in a user control so it is possible to add to the controls collection in the forms and remove it to delete it from the screen, and its background is really transparent (no color.transparent) so i can't paint the background to "clear" the previous line.
I have it static already (drawn from origin to end) but i can't animate it. I tried to add a timer in the user control but I fail to get a correct algorithm to calculate the intermediate ends of the line while it is growing.
Any help would be appreciated.
Thanks
When using animation on a Windows form you have to use another thread. Look into using a background worker: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
You don't need another thread - I have succesfully implemented Windows Forms animation.
My design:
Use a Windows.System.Forms.Timer object to call a callback function 'Animate()' at regular intervals
the Animate() function updates a property of your arrow, and then calls Invalidate() on the windows control
this all happens in the same UI thread, so yuo will not get any flicker effects (as long as your control has double duffering switched on).
I have a Control that can overlay multiple C# user controls in my GUI. This control has a semi-transparent background in order to 'grey-out' portions of the GUI and the class looks somethink like this:
public greyOutControl: UserControl
{
// Usual stuff here
protected overide OnPaint()
{
paintBackround();
base.OnPaint();
}
}
Currently the control sometimes gets caught in a loop and constantly re-draws the background, making the semi-transparent color appear less and less transparent.
My idea to combat this is the following (in broad terms):
1) Determine what controls the greyOutControl is on top of
2) call Refresh() on those controls to update the display
3) continue drawing the greyOutControl.
My question is: How can I determine which controls the greyOutControl overlaps?, or is there a way that I can refresh only the part of the GUI that greyOutControl covers?
Why don't you keep track of your transparent controls and paint them after all the other controls are drawn?. Painting anything at the top of the Z-order shouldn't cause the other controls to be repainted.
I don't see a direct way of finding the overlapping controls. I think you might need to check the whole control tree to find out that. About refreshing, you can use Control.Invalidate(Rectangle) method to specify which part to refresh.
The solution to this problem I found was to programmatically take a screen shot of the area being overlayed and then use that image as the background for the control being overlayed. This then allows you to put the alpha overlay into the image within the OnPaint() method and the control to draw itself correctly.
This does have the disadvantage that the background isn't updated in the overlapping control, but unless there was a number of event handlers watching if something changes and then update the overlayed control I cant see any way around the issue. Sometimes I regret not trying to use WPF!