自己写的一个简易win下的进度条:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace GraphicsTest
{
public delegate double HandlerColor(double x,double y);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
DrawGo();
base.OnPaint(e);
}
private void DrawGo()
{
Graphics dc = this.CreateGraphics();
Brush RedBrush = new SolidBrush(Color.Red);
Pen BluePen = new Pen(Color.Blue, 1);
Rectangle rec = new Rectangle(20, 80, 250, 30);
dc.DrawRectangle(BluePen, rec);
HandlerColor gg = new HandlerColor(GetPercent);
int i;
for (i = 0; i <= rec.Width; i = i+10)
{
double res = Handlering(gg, (double)i, rec.Width);
this.Text = "进度为" + res*100+"%";
dc.FillRectangle(RedBrush,rec.X,rec.Y,rec.Width*((float)res),rec.Height);
Thread.Sleep(500);
}
}
private static double Handlering(HandlerColor action, double x, double y)
{
double result = action(x, y);
return result;
}
private double GetPercent(double x,double y)
{
double value;
value = x / y;
return value;
}
}
}
相关界面: