欢迎来到天天文库
浏览记录
ID:40500804
大小:525.44 KB
页数:8页
时间:2019-08-03
《用C#制作带文字进度条的方法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、用C#制作带文字进度条的方法VS自带的进度条没法显示数字,不够明显。现在教你自己自制带文字的进度条的方法。1先建立新的项目选择生成控件,输入名称、确认。2在窗体上放入Panel1编写代码,写两个函数//显示进度publicvoidfunDisplayBar(intmax,intval){Imageim=newBitmap(panelProcessBar.Width,panelProcessBar.Height);//生成图片Graphicsg=Graphics.FromImage(im);//建立GRAPHICSSolidBrushbrushBackColor=
2、newSolidBrush(Color.Transparent);SolidBrushbrushGreen=newSolidBrush(Color.Lime);SolidBrushbrushBlue=newSolidBrush(Color.Blue);g.Clear(Color.White);g.FillRectangle(brushGreen,0,0,panelProcessBar.Width*val/max,panelProcessBar.Height);//填充进度FontfontTxt=newFont("宋体",10);g.DrawString(val.
3、ToString(),fontTxt,brushBlue,panelProcessBar.Width/2-8,panelProcessBar.Height/2-8);//显示文字panelProcessBar.BackgroundImage=im;}//调整大小publicvoidfunResize(intw,inth){panelProcessBar.Width=w;panelProcessBar.Height=h;}1运行一下好像什么也没有,别打!别打!看后面。2关闭解决方案,建立一个新的工程文件。1在工具箱点击右键,选择“选择项”选择浏览1选择刚才建立控件
4、的目录下生成的文件再点击确认。1新的控件有了2测试一下吧2.1添加控件,添加时间控件2.2别忘了把timer1设置成允许。1.1添加代码publicpartialclassForm1:Form{intpro;publicForm1(){InitializeComponent();myProcessBar1.funResize(myProcessBar1.Width,myProcessBar1.Height);}privatevoidtimer1_Tick(objectsender,EventArgse){pro++;if(pro>100){pro=0;}myPr
5、ocessBar1.funDisplayBar(100,pro);}}1.2运行一下了带文字的进度条生成好了。以后可方便的用了。
此文档下载收益归作者所有