Thanks very much,
It was a grate link.
Although I know vb fair, but I could change the program in C#.
Also I changed these two lines because of some problems. I don't know if it was a right work or not, but it solved a problem when the control is running.
this.Invalidate();
codes in C#:
private int min = 0;
private int max = 100;
private int val = 0;
private Color barColor = Color.Blue;
protected override void OnResize(EventArgs e)
{
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush brush = new SolidBrush(barColor);
float percent = ((float)val - min) / (max - min);
Rectangle rect = this.ClientRectangle;
rect.Width = (int)(rect.Width * percent);
g.FillRectangle(brush, rect);
Draw3DBorder(g);
brush.Dispose();
g.Dispose();
}
public int Minimum
{
get
{
return min;
}
set
{
if (value < 0)
min = 0;
if (value > max)
{
min = value;
}
if (val < min)
val = min;
this.Invalidate();
}
}
public int Maximum
{
get
{
return max;
}
set
{
if (value < min)
min = value;
max = value;
if (val > max)
val = max;
this.Invalidate();
}
}
public int Value
{
get
{
return val;
}
set
{
int oldvalue = val;
if (value < min)
val = min;
else if (value > max)
val = max;
else
val = value;
float percent;
Rectangle newvalueRect = this.ClientRectangle;
Rectangle oldvalueRect = this.ClientRectangle;
percent = (val - min) / (max - min);
newvalueRect.Width = (int)(newvalueRect.Width * percent);
percent = (oldvalue - min) / (max - min);
oldvalueRect.Width = (int)(oldvalueRect.Width * percent);
Rectangle updateRect = new Rectangle();
if (newvalueRect.Width > oldvalueRect.Width)
{
updateRect.X = oldvalueRect.Size.Width;
updateRect.Width = newvalueRect.Width - oldvalueRect.Width;
}
else
{
updateRect.X = newvalueRect.Size.Width;
updateRect.Width = oldvalueRect.Width - newvalueRect.Width;
}
updateRect.Height = this.Height;
this.Invalidate();
}
}
public Color ProgressBarColor
{
get
{
return barColor;
}
set
{
barColor = value;
this.Invalidate();
}
}
private void Draw3DBorder(Graphics g)
{
int PenWidth = (int)Pens.White.Width;
g.DrawLine(Pens.DarkGray,
new Point(this.ClientRectangle.Left, this.ClientRectangle.Top),
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top));
g.DrawLine(Pens.DarkGray,
new Point(this.ClientRectangle.Left, this.ClientRectangle.Top),
new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth));
g.DrawLine(Pens.White,
new Point(this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth),
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
g.DrawLine(Pens.White,
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top),
new Point(this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth));
}