WinFrom 进度条控件怎么用?

zhaozhijun0207 2009-01-06 09:12:52


窗体上有个Button控件,
点击控件,就去执行一些操作,

操作完成后,进度条就满了.然后隐藏进度条控件
...全文
369 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cymyren 2009-01-06
  • 打赏
  • 举报
回复
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 WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

for (int i = 0; i < 100; i++)
{
this.progressBar1.Value = i;

Thread.Sleep(20); //设为20就可以了
}
this.progressBar1.Visible = false;

}


}
}
cymyren 2009-01-06
  • 打赏
  • 举报
回复
恩 4楼说的对 要把
Thread.Sleep(200);
放在 for循环里,效果就出来了。
mengdqjiangxi 2009-01-06
  • 打赏
  • 举报
回复
2楼正解
ailuo97 2009-01-06
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
public partial class frmPrograss : Form
{
public frmPrograss()
{
InitializeComponent();
}

private int GetStep()
{
Random ran = new Random(DateTime.Now.Millisecond);
return ran.Next(10, 30);
}

private string[] arr ={
"系统加载数据中,请稍候.",
"系统加载数据中,请稍候...",
"系统加载数据中,请稍候.....",
"系统加载数据中,请稍候.......",
"系统加载数据中,请稍候..........",
"系统加载数据中,请稍候..............",
"系统加载数据中,请稍候.................",
"系统加载数据中,请稍候....................",
"系统加载数据中,请稍候........................",
};

private int i = 2;

private void timer1_Tick(object sender, EventArgs e)
{
if (this.label1.ForeColor == Color.Black)
{
this.label1.ForeColor = Color.Red;

}
else
{
this.label1.ForeColor = Color.Black;
}

if (i <= arr.Length - 1)
{
this.label1.Text = arr[i];
i++;
}

int step = this.GetStep();
if (this.progressBar1.Value + step < this.progressBar1.Maximum)
{
this.progressBar1.Value = this.progressBar1.Value + step;
return;
}
else
{
this.timer1.Enabled = false;
this.progressBar1.Value = this.progressBar1.Maximum;
Form1 frm = new Form1();
this.Hide();
frm.Show();

}

}

private void frmPrograss_Load(object sender, EventArgs e)
{




this.timer1.Enabled = true;
}
}
}
lunat 2009-01-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 netusemaster 的回复:]
C# code


private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 100; i++)
{
this.progressBar1.Value = i;

}

Thread.Sleep(200); //以免太快没效果

this.progressBar1.Visible = false;
}
[/Quote]

^_^ Thread.Sleep(200);应该放到for里面吧
wolf1118baby 2009-01-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 netusemaster 的回复:]
C# code


private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 100; i++)
{
this.progressBar1.Value = i;

}

Thread.Sleep(200); //以免太快没效果

this.progressBar1.Visible = false;
}
[/Quote]
正解,你最好多看看msdn
netusemaster 2009-01-06
  • 打赏
  • 举报
回复



private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 100; i++)
{
this.progressBar1.Value = i;

}

Thread.Sleep(200); //以免太快没效果

this.progressBar1.Visible = false;
}
lizhengnan 2009-01-06
  • 打赏
  • 举报
回复

Progressbar1.value=0;
Progressbar1.maximize=100;
for(int =0;i<100;i++)
{
Progressbar1.value=Progressbar1.value+1;
Progressbar1.update();
}
Progressbar1.visible=false;

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧