|
C# 绘制进度条
1. 用lable 显示,背景 颜色去不掉,
2. 用 GDI+ 绘制 但是 闪烁 很厉害!
请大家帮忙分析下,这种情况怎么解决!
代码 如下!
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
}
private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(PB1);
th.IsBackground=true;
th.Start();
}
void PB1()
{
string strnumber;
for (int i = 0; i <= 5000; i++)
{
Thread.Sleep(10);
strnumber = ((i*100)/5000).ToString() + "%";
//Bitmap bmp = new Bitmap(84, 28);
Graphics g = progressBar1.CreateGraphics();
g.DrawString(strnumber, new Font("宋体", 20, FontStyle.Bold), Brushes.Blue, new PointF(progressBar1.Width/2,progressBar1.Height/2-15));
progressBar1.Value = i;
// pictureBox1.Image = bmp;
label1.Text = ((i * 100) / 5000).ToString() + "%";
}
//string strnumber;
//for (int i = 0; i <= 5000; i++)
//{
// Thread.Sleep(10);
// strnumber = ((i * 100) / 5000).ToString() + "%";
// Bitmap bmp = new Bitmap(84, 28);
// Graphics g = Graphics.FromImage(bmp);
// g.DrawString(strnumber, new Font("宋体", 10, FontStyle.Bold), Brushes.Blue, new PointF(bmp.Width / 2, bmp.Height / 2 - 10));
// progressBar1.Value = i;
// pictureBox1.Image = bmp;
// label1.Text = ((i * 100) / 5000).ToString() + "%";
//}
|
|