请问高手,如何做一个加载进度条
比如我想在打开某窗体,前显示进度条(可以使用文字或图片),因为这个窗体数据可能比较大,需要一个等待过程。该怎么做?
[解决办法]
:)
方法很多,例如:
1、在任务的变化处,不断改变进度条的值,这样,就能直观地显示任务进度。
2、计算大概需要多少时间,按时间来改变进度条的值。
3、做一个循环的图片,在任务进行中显示,任务完成就关闭。
……
[解决办法]
<form name=loading>
<p align=center> <font color= "#800080 " size= "2 "> 载入中,请稍等 </font> <font color= "#FFFF00 " size= "2 " face= "Arial "> ... </font>
<input type=text name=chart size=46 style= "font-family:Arial; font-weight:bolder; color:#800080; background-color:#C0FFFF; padding:0px; border-style:none; ">
<input type=text name=percent size=47 style= "color:#800080; text-align:center; border-width:medium; border-style:none; ">
<script language= "JavaScript ">
var bar=0 <!--声明变量-->
var line= "|| " <!--loading条的样式-->
var amount= "|| " <!--loading条的样式-->
count() <!--直接调用count()函数-->
function count(){
bar=bar+2 <!--每次增加两个bar-->
amount =amount + line <!--loading条每次增加两条竖线-->
document.loading.chart.value=amount <!--刷新进展条-->
document.loading.percent.value=bar+ "% " <!--计算出百分比-->
if (bar <99)
{setTimeout( "count() ",100);} <!--每0.1秒进展条加1-->
else
{window.location = "http://www.JavaScript.com/ ";} <!--进展条满后,显示另一个网页-->
} </script>
[解决办法]
方法很多
[解决办法]
主窗体先Hide掉,打开进度窗体。主窗体每完成一个进度就向进度窗体发一条消息,通知进度窗体更新进度条。
[解决办法]
winform实现起来更简单吧,同意wzd24(牧野)(衣带渐宽终不悔,为伊消得人憔悴)
[解决办法]
公司的一个进度条,你自己看看吧
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Threading;
namespace SM2560L
{
/// <summary>
/// movingbar 的摘要说明。
/// </summary>
public class MovingBar : System.Windows.Forms.UserControl
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label box;
private Thread movebar;
public int xx=1;
public MovingBar()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何初始化
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
this.movebar.Abort();
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.box = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// box
//
this.box.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.box.BackColor = System.Drawing.SystemColors.Control;
this.box.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.box.Location = new System.Drawing.Point(1, 1);
this.box.Name = "box ";
this.box.Size = new System.Drawing.Size(454, 22);
this.box.TabIndex = 0;
//
// movingbar
//
this.AutoScroll = true;
this.BackColor = System.Drawing.SystemColors.Control;
this.Controls.Add(this.box);
this.Name = "movingbar ";
this.Size = new System.Drawing.Size(456, 24);
this.Load += new System.EventHandler(this.movingbar_Load);
this.ResumeLayout(false);
}
#endregion
private void goon()
{
try
{
ThreadStart myThreadDelegate = new ThreadStart(moveon);
movebar=new Thread(myThreadDelegate);
movebar.Priority=ThreadPriority.Highest;
movebar.Name= "sm2560l_probar ";
movebar.IsBackground=true;
movebar.Start();
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}
private void movingbar_Load(object sender, System.EventArgs e)
{
goon();
}
public void start()
{
try
{
if(movebar.ThreadState==ThreadState.Suspended)
{
this.movebar.Resume();
}
else
{
if(movebar.ThreadState==ThreadState.WaitSleepJoin)
{
movebar.Interrupt();
}
else
{
if(movebar.ThreadState==ThreadState.Unstarted)
{
movebar.Start();
}
else
{
Thread.Sleep(300);
movebar.Start();
}
}
}
}
catch
{}
}
public void stop()
{
this.movebar.Suspend();
}
private void moveon()
{
try
{
Graphics g=this.box.CreateGraphics();
int x=0,
y=0,
w=this.box.Width,
h=this.box.Height;
LinearGradientBrush lgbl=new LinearGradientBrush(new Rectangle(0,0,12,h),this.box.BackColor,Color.FromArgb(60,150,60),0f );
Pen pen=new Pen(this.box.BackColor,10);
int i=x;
while(true)
{
g.FillRectangle(lgbl,i,y,i,y+h);
g.DrawLine(pen,i,y,i,y+h);
Thread.Sleep(25);
i+=2;
if(i> =x+w) i=x;
}
}
catch
{}
}
}
}