asp.net进度条的实现(附demo)

上一篇只是备份了下代码,这次是可以独立运行的demo。
demo模拟的是发送多封邮件过程中进度条的显示。其中图片设计的不太规范,所以js控制进度条移动的代码有点乱,这个大家可以替换成自己的,这里只是演示作用。
进度条动态增长的原理是:一个中间扣空的酒瓶子图片,这个图片下面放另外一张图片,移动下层图片以实现进度条增长效果。
None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Text;
None.gif
using  System.Threading;
None.gif
namespace  guagedemo
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// guagedemo 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class guagedemo : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public StringBuilder textpile=new StringBuilder(@"<table><tr><td background=images/titlebg.gif height=32 class=t2 width=100%>&nbsp;&nbsp;发送邮件</td></tr><tr><td><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1 bgcolor=#ADDB52></td><td width=561 valign=top><table width=100% border=0 cellspacing=0 cellpadding=0 background=images/tablebg.gif><tr><td height=6 colspan=2></td></tr>");
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            objMailclass mail=new objMailclass();
InBlock.gif            mail.mail1
=new objMail[3];
InBlock.gif            mail.mail1cx
=3;
InBlock.gif            mail.mail2
=new objMail[3];
InBlock.gif            mail.mail2cx
=3;
InBlock.gif            mail.mail3
=new objMail[3];
InBlock.gif            mail.mail3cx
=3;
InBlock.gif            mail.mail1[
0]=new objMail();
InBlock.gif            mail.mail1[
0].strSubject="类别1邮件:邮件1";
InBlock.gif            mail.mail1[
1]=new objMail();
InBlock.gif            mail.mail1[
1].strSubject="类别1邮件:邮件2";
InBlock.gif            mail.mail1[
2]=new objMail();
InBlock.gif            mail.mail1[
2].strSubject="类别1邮件:邮件3";
InBlock.gif            mail.mail2[
0]=new objMail();
InBlock.gif            mail.mail2[
0].strSubject="类别2邮件:邮件1";
InBlock.gif            mail.mail2[
1]=new objMail();
InBlock.gif            mail.mail2[
1].strSubject="类别2邮件:邮件2";
InBlock.gif            mail.mail2[
2]=new objMail();
InBlock.gif            mail.mail2[
2].strSubject="类别2邮件:邮件3";
InBlock.gif            mail.mail3[
0]=new objMail();
InBlock.gif            mail.mail3[
0].strSubject="类别3邮件:邮件1";
InBlock.gif            mail.mail3[
1]=new objMail();
InBlock.gif            mail.mail3[
1].strSubject="类别3邮件:邮件2";
InBlock.gif            mail.mail3[
2]=new objMail();
InBlock.gif            mail.mail3[
2].strSubject="类别3邮件:邮件3";
InBlock.gif            intipagetop(mail);
ExpandedSubBlockEnd.gif        }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
输出进度条显示#region 输出进度条显示
InBlock.gif        
private void process(string intSProcess,string intEProcess,string text)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"<script language=javascript>itop="+intSProcess+";ileft=mydiv2.offsetLeft;function move(){if(mydiv2.style.top!='"+intEProcess+"px'){ileft=ileft-1;itop=itop-2;mydiv2.style.top=itop-2;mydiv2.style.left=ileft-1;if(haha.value=='0'){mydiv3.innertText='100%';}else{ttt=(0-itop-70)/4.14;if(ttt>100)ttt=100;aaa=ttt.toString();if(ttt==100){mydiv3.innertText='100%';}else{mydiv3.innerText=aaa.slice(0,aaa.lastIndexOf('.'))+'%';}}setTimeout(move,10)}}");
InBlock.gif            
if(text!="")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string temp=text.Substring(5);
InBlock.gif                
string temp2=text.Substring(0,5);
InBlock.gif                textpile.AppendFormat(
@"<tr><td width=6% height=30 align=center><img src=images/titlelog.gif width=10 height=10 /></td><td width=94%><span class=t1>{1} </span>  <span class=t2>{0}</span></td></tr>",temp,temp2);
InBlock.gif                Response.Write(
"mydiv4.innerHTML='<table width=563 border=0 cellspacing=0 cellpading=0>"+textpile.ToString()+"</table></td><td width=1 bgcolor=#ADDB52></td></tr></table></td></tr><tr><td height=5 background=images/bottomline.gif></td></tr></table></table>';");
ExpandedSubBlockEnd.gif            }

InBlock.gif            Response.Write(
"move();</script>");
InBlock.gif            Response.Flush();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif        
private void intipagetop(objMailclass maill)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif                
进度条初始化#region 进度条初始化
InBlock.gif                Response.Write(
@"<html><head>
InBlock.gif<meta http-equiv=Content-Type content=text/html; charset=gb2312 />
InBlock.gif<title>无标题文档</title>
InBlock.gif<style type=text/css>
InBlock.gif<!--
InBlock.gif.t1 {
InBlock.gif    font-family: 
"+"\"宋体\""+@";
InBlock.gif    font-size: 14px;
InBlock.gif    font-style: normal;
InBlock.gif    line-height: normal;
InBlock.gif    font-weight: bold;
InBlock.gif    font-variant: normal;
InBlock.gif    text-transform: none;
InBlock.gif    color: #639500;
InBlock.gif    text-decoration: none;
InBlock.gif}
InBlock.gif.t2 {
InBlock.gif    font-family: 
"+"\"宋体\""+@";
InBlock.gif    font-size: 12px;
InBlock.gif    font-style: normal;
InBlock.gif    line-height: normal;
InBlock.gif    font-weight: bold;
InBlock.gif    font-variant: normal;
InBlock.gif    text-transform: none;
InBlock.gif    color: #000000;
InBlock.gif    text-decoration: none;
InBlock.gif}
InBlock.gif-->
InBlock.gif</style>
InBlock.gif</head><body style='overflow:-Scroll;overflow-y:hidden;overflow-x:hidden;'><input id=haha value=1 type=hidden>
");
InBlock.gif                Response.Write(
"<div id='mydiv' style='position:absolute;width:500;height:600;top:-100px;left:-300px;z-index:100;'><img src=images/process_02.gif>");
InBlock.gif                Response.Write(
"</div>");
InBlock.gif                Response.Write(
"<div id='mydiv2' style='position:absolute;top:100px;left:50px;z-index:99;'><img src=images/process_03.gif>");
InBlock.gif                Response.Write(
"</div>");
InBlock.gif                Response.Write(
"<div id='mydiv4' style='position:absolute;top:72px;left:360px;z-index:101;'>");
InBlock.gif                Response.Write(
"</div>");
InBlock.gif                Response.Write(
"<div  style='background:url(images/process_01.gif) no-repeat;position:absolute;width=96px;height=103px;top:72px;left:240px;z-index:101;'><table width=100% height=100% border=0 cellspacing=0 cellpading=0><tr><td height=100% width=100%  valign=middle align='center'><div id='mydiv3' >12%</div></td></tr></table>");
InBlock.gif                Response.Write(
"</div>");
InBlock.gif                Response.Write(
"<script language=javascript>");
InBlock.gif                Response.Write(
@"function StartShowWait(){mydiv.style.visible='visible';mydiv2.style.visible='visible';mydiv4.style.visible='visible';} ");
InBlock.gif                Response.Write(
"StartShowWait();</script>");
InBlock.gif                Response.Write(
@"</body></html>");
InBlock.gif                Response.Flush();
ExpandedSubBlockEnd.gif                
#endregion

InBlock.gif                process(
"-70","-110","");
InBlock.gif                Thread.Sleep(
200);
InBlock.gif                process(
"-110","-156","");
InBlock.gif                Thread.Sleep(
200);    
ContractedSubBlock.gifExpandedSubBlockStart.gif                
发送邮件#region 发送邮件
ContractedSubBlock.gifExpandedSubBlockStart.gif                
根据邮件数量,进行百分比动态分配#region 根据邮件数量,进行百分比动态分配
InBlock.gif                
int cx=maill.mail1cx+maill.mail2cx+maill.mail3cx;
InBlock.gif                
int temp1;
InBlock.gif                
if(((330*maill.mail1cx)/cx)%2>0)
InBlock.gif                    temp1
=(330*maill.mail1cx)/cx+1;
InBlock.gif                
else
InBlock.gif                    temp1
=(330*maill.mail1cx)/cx;
InBlock.gif                
int temp2;
InBlock.gif                
if(((330*(maill.mail1cx+maill.mail2cx))/cx)%2>0)
InBlock.gif                    temp2
=(330*(maill.mail1cx+maill.mail2cx))/cx+1;
InBlock.gif                
else
InBlock.gif                    temp2
=(330*(maill.mail1cx+maill.mail2cx))/cx;
InBlock.gif                
int bx1;
InBlock.gif                
if(maill.mail1cx!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if((temp1/maill.mail1cx)%2>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bx1
=temp1/maill.mail1cx+1;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bx1
=temp1/maill.mail1cx;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    bx1
=0;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
int bx2;
InBlock.gif                
if(maill.mail2cx!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(((temp2-temp1)/maill.mail2cx)%2>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bx2
=(temp2-temp1)/maill.mail2cx+1;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bx2
=(temp2-temp1)/maill.mail2cx;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    bx2
=0;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
int bx3;
InBlock.gif                
if(maill.mail3cx!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(((330-temp2)/maill.mail3cx)%2>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bx3
=(330-temp2)/maill.mail3cx+1;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bx3
=(330-temp2)/maill.mail3cx;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    bx3
=0;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif                
#endregion

InBlock.gif                
for(int i=0;i<maill.mail1cx;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//此处延时半秒模拟发送邮件
InBlock.gif
                    Thread.Sleep(500);    
InBlock.gif                    process(
"-"+Convert.ToString(156+bx1*i),"-"+Convert.ToString(156+bx1*(i+1)),maill.mail1[i].strSubject);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
for(int i=0;i<maill.mail2cx;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//此处延时半秒模拟发送邮件
InBlock.gif
                    Thread.Sleep(500);    
InBlock.gif                    process(
"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*(i+1)),maill.mail2[i].strSubject);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
for(int i=0;i<maill.mail3cx;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//此处延时半秒模拟发送邮件
InBlock.gif
                    Thread.Sleep(500);    
InBlock.gif                    process(
"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*maill.mail2cx+bx3*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*maill.mail2cx+bx3*(i+1)),maill.mail3[i].strSubject);
ExpandedSubBlockEnd.gif                }

InBlock.gif                textpile.Append(
"<tr><td height=30 colspan=2 align=center class=t1>发送成功!</td></tr><tr><td height=10 colspan=2 align=center class=t1></td></tr><tr><td height=40 colspan=2 align=center class=t1><img  style='cursor:hand;' οnclick='javascript:location=location.href.toString();' src=images/returnbutton.gif width=71 height=25 />&nbsp;&nbsp;&nbsp;&nbsp;<img src=images/closebutton.gif  style='cursor:hand;' οnclick='javascript:window.close();' width=71 height=25 /></td></tr>");
InBlock.gif                Response.Write(
"<script language='javascript'>haha.value='0';mydiv3.innerText='100%';mydiv4.innerHTML=\""+textpile.ToString()+@"</table></td><td width=1 bgcolor=#ADDB52></td></tr></table></td></tr><tr><td height=5 background=images/bottomline.gif></td></tr></table>"+"\";setTimeout(finish,1200); function finish(){mydiv3.innerText='100%';}</script></body></html>");
InBlock.gif                Response.Flush();
InBlock.gif                Response.Close();
ExpandedSubBlockEnd.gif                
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public class objMail
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
public string strMail;
InBlock.gif            
public string strSubject;
InBlock.gif            
public string strMailType;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public class objMailclass
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
public objMail[] mail1;
InBlock.gif            
public int mail1cx=0;
InBlock.gif            
public objMail[] mail2;
InBlock.gif            
public int mail2cx=0;
InBlock.gif            
public objMail[] mail3;
InBlock.gif            
public int mail3cx=0;
ExpandedSubBlockEnd.gif        }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
demo下载  

转载于:https://www.cnblogs.com/suntears/archive/2007/04/24/724833.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值