 |
|
 |
Really superb article.It Helps beginners very much. Thanks a lot BOSS...
|
|
|
|
 |
|
 |
Hello.
I would like to make an free control mainly based on your project.
I will just add few more features to your class.
if you are ok with it, here the class's header i've pre-wrote; hopping you will be ok with it:
Best Regards.
|
|
|
|
 |
|
 |
Well my job is allmost over; just few improvement to add, also the Shape property to implement.
here the current result
On this picture, you see :
1st progressbar : simply with default properties values.
2nd progressbar : with properties set so the progressbar appareance is close of the .NET progressbar
3rd progressbar : with DisplayPercent property set to false, and using ValueChanged event to customize displayed text; also i've set Font to bold, and ForeColor to white.
4th & 5th progressbars : with TextAlign set to left (with margin.left property set to 15); 2nd one with text align set to Right
Last progressbar is a fake, because often people asks how to do a K2000 effet, i simply used the .NET progressbar, and set its style to K2000
Many other features and improvement into my class, described with comments (events, properties added, minor bugfixes,and so on)
Just awaiting agreement to publish...
|
|
|
|
 |
|
|
 |
|
 |
it's more interesting to color every step in his own color
|
|
|
|
 |
|
 |
Here's what I have before I say yours:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ProgressBarSimple2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Interval = 1000;
timer1.Enabled = true;
timer2.Interval = 1000;
timer2.Enabled = true;
timer3.Interval = 1000;
timer3.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 5)
{
progressBar1.Value += 1;
progressBar1.Update();
}
else
{
progressBar1.Value = 0;
progressBar1.Update();
}
}
private void timer2_Tick(object sender, EventArgs e)
{
if (progressBar2.Value < 8)
{
progressBar2.Value += 1;
progressBar2.Update();
}
else
{
progressBar2.Value = 0;
progressBar2.Update();
}
}
private void timer3_Tick(object sender, EventArgs e)
{
if (progressBar3.Value < 10)
{
progressBar3.Value += 1;
progressBar3.Update();
}
else
{
progressBar3.Value = 0;
progressBar3.Update();
}
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void progressBar2_Click(object sender, EventArgs e)
{
}
private void progressBar3_Click(object sender, EventArgs e)
{
}
}
|
|
|
|
 |
|
 |
Nice control. Rather than using timers, How about introducing the marquee effect similar to what is available with VB.NET express 2008's progressbar ?
|
|
|
|
 |
|
 |
Excellent,fri
sdfsf
|
|
|
|
 |
|
 |
Very good.
Two hours for rescripting it in VB application (and undestand your C code) with no problem.
Excellent !
|
|
|
|
 |
|
 |
Alan,
To test your control I placed it on a Form and then added a loop that gets activated by clicking on a Button (which calls event Button_Click). In the loop I just called PerformUpdate() method.
The problem was that the control did not get redrawn until the Button_Click finished.
I replaced all the calls to Invalidate() by calls to UpdateProgressBar() which is defined below.
I haven't had much experience with GDI+ so if you have a better way, please let me know.
private void UpdateProgressBar()
{
PaintEventArgs e = new PaintEventArgs(this.CreateGraphics(),this.ClientRectangle);
OnPaint(e);
}
|
|
|
|
 |
|
 |
Invalidate waits for the best time to paint. To force a paint you have to use the Refresh(); method call.
|
|
|
|
 |
|
 |
Hello Alan, I wonder if I can post a new article based VERY much on your code. Basically I used the progress bar you did but I didn’t like how it looks. So I made it look more like XP style.
Enhancements:
- XP look.
- Bars now are drawn like XP progress bar (I mean the hole bar not only a part of it)
Basically this is it. You can email you how the new progress bar looks like.
P.S. Great work.
|
|
|
|
 |
|
 |
Thanks DDISoft,
I am very happy to see the improvements you did on Color ProgressBar. You're very welcome to post a new article with these improvements. Thanks again!
Alan
|
|
|
|
 |
|
|
 |
|
 |
Application.EnableVisualStyles();
Application.DoEvents();
This will give you the xp-look this certainly isn't boring is it?
Diablo
|
|
|
|
 |
|
 |
Thank you for this code, it has made me much happier, not having to suffer progress bars in Battleship Grey under the "Silver" theme in XP, and saved me countless hours tyring to do something which imo should have been included with .NET studio in the first place.
/ karv
|
|
|
|
 |
|
 |
How to clear progress bar?
|
|
|
|
 |
|
 |
I would imagine you just set the value to 0 like normal progress bars.
|
|
|
|
 |
|
 |
I believe I have coded a progress indicator. I have been writing my own ProgressBar (it extends the regular progressbar with your coloring methods - your code was very useful, I only modified a few things, well written and with the ability to automatically copy a file to another location and display the percentage of that operation as it is proceeding), and I also was hunting for a method to draw the percentage, and draw it centered in the progressbar. After a little messing around with PointF() and GDI+, I came up with this:
Font percentageFont = new Font("Arial",Height / 4);
e.Graphics.DrawString(Value.ToString() + "%",percentageFont,new SolidBrush(Color.Black),new PointF((float)(Width / 2 - 1.5 * percentageFont.Size),Height / 2 - percentageFont.GetHeight(e.Graphics) / 2));
You can also replace
SolidBrush bgBrush = new SolidBrush(bgColor);
e.Graphics.FillRectangle(bgBrush, this.ClientRectangle);
with
e.Graphics.Clear(bgColor);
In all my tests, this has worked well, even with resizing controls and at several different resolutions (1024x768, 1152x864,800x600). Hope it helps!
|
|
|
|
 |
|
 |
Nice. I like it.
www.CoderForRent.com
GET A PROGRAMMING JOB TODAY! We have the cheapest rates anywhere.
FREELANCE WORK AVAILABLE NOW!
|
|
|
|
 |
|
|
 |
|
 |
Hi
Looks nice
Try using a GradientBrush fill to make things more flexible.
Cheers
leppie
|
|
|
|
 |
|
 |
But will GradientBrush fill have the same 3D feel? Can you show me an example?
Thank!
|
|
|
|
 |
|
 |
You could use this as a basis for your painting.
This piece of code assumes
_col as the Color variable storing the ProgressBar's color
_min as the Minimum value
_max as the Maximum value
_val as the current Value
Feel free to include it in your source!
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Color dCol = ControlPaint.Dark(_col);
Color ddCol = ControlPaint.Dark(_col);
SolidBrush sb = new SolidBrush(ddCol);
e.Graphics.FillRectangle(sb, this.ClientRectangle);
sb.Dispose();
int w = (this.Width*_val)/(_max-_min);
if (w==0) return;
Rectangle topRc = new Rectangle(0, 0, w, this.Height/2);
Rectangle botRc = new Rectangle(0, this.Height/2, w, this.Height/2);
LinearGradientBrush lgb;
lgb = new LinearGradientBrush(new Point(0, 0), new Point(0, this.Height/2), dCol, _col);
e.Graphics.FillRectangle(lgb, topRc);
lgb.Dispose();
lgb = new LinearGradientBrush(new Point(0, this.Height/2-1), new Point(0, this.Height), _col, dCol);
e.Graphics.FillRectangle(lgb, botRc);
lgb.Dispose();
}
|
|
|
|
 |
|
 |
Thanks mav.northwind, I rewrote the onPaint() method based on you suggestion. The updated project is available now.
You're credited above in the article.
Thanks again!!!
|
|
|
|
 |