gradient progressbar

  • Thread starter Thread starter Thomas Kehl
  • Start date Start date
T

Thomas Kehl

Hi!

Does anyone have a tipp for me where can I found (or how can I programm) a
"progressbar" which has a gradient and the color go from the left side to
right and back ... I should have a waiting-progressbar :-)

Thanks
Thomas
 
Thomas,
I would use a System.Drawing.Drawing2D.LinearGradientBrush to get the color
gradient.

I would start a new Control (inherit System.Windows.Forms.Control) that had
properties similar to System.Windows.Forms.ProgressBar, plus 2 color
properties (for first & second color of the gradient).

In the OnPaint event of the control I would fill the client area with my
brush.

Then depending on the effect you desire I would set different options on the
brush.

Charles Petzold's book "Programming Microsoft Windows With Microsft Visual
Basic .NET" has a chapter where is discusses the different effects possible
with the LinearGradientBrush.

Hope this helps
Jay
 
How about something like this:

using System.Drawing;
using System.Drawing.Drawing2D;
....
public void SetPercentComplete( int percent )
{
int width = (int)Math.Floor(pnlProgress.ClientRectangle.Width *
((double)percent)/100.0);
int height = pnlProgress.ClientRectangle.Height;
if( width > 0 && height > 0 )
{
pnlProgress.Invalidate(new Rectangle( pnlProgress.ClientRectangle.X,
pnlStatus.ClientRectangle.Y, width, height));
}
}
private void pnlProgress_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
if( e.ClipRectangle.Width > 0 )
{
LinearGradientBrush brBackground = new
LinearGradientBrush(e.ClipRectangle, System.Drawing.Color.FromArgb(255, 0,
0), Color.FromArgb(0, 255, 0), LinearGradientMode.Horizontal);
e.Graphics.FillRectangle(brBackground, e.ClipRectangle);
}
}

Tom Clement
Apptero, Inc.
 
Back
Top