Scirious wrote:
Ok, sorry for the preveious behavior. I've already search Google and some
foruns for this but there is yet one question unanswered. How do I add a
progress bar to a button? Would Windows Buttons behave like a container
itself and allow me to add other components to it the same way SWING or QT
do?
TIA,
Scirious.
Hi Scirious,
I've written you a class, that may do what you want. Perhaps it will be of
some use.
You need to add using clauses for System.Drawing and System.Windows.Forms,
along with the usual System and whatnot.
///
public class ProgressButton : Button
{
private int _max;
private int _value;
public ProgressButton ( )
{
this.TextAlign = ContentAlignment.TopCenter;
_max = 100;
_value = 0;
}
public int MaximumProgressValue
{
get { return _max; }
set
{
_max = value;
if ( this.ProgressValue > _max )
this.ProgressValue = _max;
}
}
public int ProgressValue
{
get { return _value; }
set
{
_value = value;
if ( _value > _max )
_value = _max;
else if ( _value < 0 )
_value = 0;
this.Invalidate();
}
}
protected override void OnPaint ( PaintEventArgs pevent )
{
base.OnPaint( pevent );
const int padding = 6;
const int barHeight = 16;
Rectangle progressRect = new Rectangle( padding,
this.Height - padding - barHeight,
this.Width - ( padding * 2 ),
barHeight );
ProgressBarRenderer.DrawHorizontalBar( pevent.Graphics,
progressRect );
progressRect.Inflate( -3, -3 );
progressRect.Width = (int)
( progressRect.Width * ( (double) _value / _max ) );
ProgressBarRenderer.DrawHorizontalChunks( pevent.Graphics,
progressRect );
}
}
///
Normally, I don't like putting parameters on seperate lines, but to conform
to news group standards, I've done it.
To use, add the control to your form as you normally would.
+ MaximumProgressValue is the maximum value of your progress bar.
+ ProgressValue is the value of the progress bar.
It looks okay using Windows XP themes. I haven't tested it anywhere else.
--
Hope this helps,
Tom Spink