C#进度轴控件分享
当执行长时间后台处理时,你是否希望软件给你一个反馈,让你了解程序执行进度。进度轴帮你忙,轻松掌握全局动态。你的进度你做主!进度轴分为横版和纵版总有一版适合你!
应用了事件机制假如有更好的方法欢迎交流,假如对您有用请顶一下。
载入时间轴控件
///<summary> ///载入时间轴控件 ///2015-04-16 ///吴海龙 ///</summary> publicvoidLoadTimeAxis() { SortedDictionary<string,string>sdict=newSortedDictionary<string,string>(); sdict.Add("1","读取配置"); sdict.Add("2","选择模板"); sdict.Add("3","确认数据"); sdict.Add("4","生成代码"); uta=newuctlTimeAxis(sdict,1); uta.lc=newToolFunction.uctlTimeAxis.TimeAxisClick(SayHello); CommonFunction.AddForm3(splitContainer4.Panel2,uta); }
panel容器中添加控件
///<summary> ///项panel容器中添加控件 ///</summary> ///<paramname="p">容器panel</param> ///<paramname="uc">显示的usercontrol</param> publicstaticvoidAddForm3(Panelp,UserControluc) { p.Controls.Clear(); p.Controls.Add(uc); uc.Dock=DockStyle.Fill; }
初始化纵版界面
///<summary> ///初始化垂直进度轴 ///2015-04-15 ///吴海龙 ///</summary> publicvoidInitVerticalTimeAxis() { try { intTempCenterOfThePieY=CenterOfTheCircleY; using(Graphicsg=this.CreateGraphics()) { g.SmoothingMode=SmoothingMode.HighQuality;//使绘图质量最高,即消除锯齿 g.InterpolationMode=InterpolationMode.HighQualityBicubic; g.CompositingQuality=CompositingQuality.HighQuality; g.DrawString("正在执行:",f1,Brushes.Black,newPointF(CenterOfTheCircleX,5)); g.DrawLine(p3,newPoint(LineStartX,TempCenterOfThePieY),newPoint(LineStartX,(sdict.Keys.Count-1)*CircleSpace+TempCenterOfThePieY)); foreach(variteminsdict.Keys) { g.FillEllipse(Brushes.Gray,CenterOfTheCircleX-CircleRadius,TempCenterOfThePieY-CircleRadius,CircleRadius*2,CircleRadius*2); g.FillEllipse(Brushes.White,CenterOfTheCircleX-PieRadius2,TempCenterOfThePieY-PieRadius2,PieRadius2*2,PieRadius2*2); g.DrawString(sdict[item],f1,Brushes.DarkGray,newPointF(ItemStartX,TempCenterOfThePieY-ItemFixY)); Labell=newLabel(); l.Name=item; l.Location=newPoint(ItemStartX,TempCenterOfThePieY-ItemFixY); l.Text=sdict[item]; l.Click+=newEventHandler(l_Click); //l.Click+=newEventHandler(l_Click2); this.Controls.Add(l); TempCenterOfThePieY=TempCenterOfThePieY+CircleSpace; } } } catch(Exceptionexp) { CommonFunction.WriteLog(exp,"绘制失败"); } }
纵版进度轴步进方法
///<summary> ///垂直步进方法 //////2015-04-16 ///吴海龙 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> publicvoidSetVerticalStep(objectsender,KeyValueEventArgse) { intTempCenterOfThePieY=CenterOfTheCircleY; if(""==KeyValueEventArgs.Key) { return; } using(Graphicsg=this.CreateGraphics()) { g.SmoothingMode=SmoothingMode.HighQuality;//使绘图质量最高,即消除锯齿 g.InterpolationMode=InterpolationMode.HighQualityBicubic; g.CompositingQuality=CompositingQuality.HighQuality; foreach(variteminsdict.Keys) { g.DrawString(sdict[item],f1,Brushes.Green,ItemStartX,TempCenterOfThePieY-ItemFixY); g.DrawEllipse(Pens.Green,CenterOfTheCircleX-CircleRadius,TempCenterOfThePieY-CircleRadius,CircleRadius*2,CircleRadius*2); g.DrawLine(p2,newPoint(LineStartX,LineStartY),newPoint(LineStartX,TempCenterOfThePieY)); g.FillEllipse(Brushes.Green,CenterOfTheCircleX-PieRadius,TempCenterOfThePieY-PieRadius,PieRadius*2,PieRadius*2); if(item==KeyValueEventArgs.Key) { break; } TempCenterOfThePieY=TempCenterOfThePieY+CircleSpace; } } }
画图属性字段
///<summary> ///蓝色宽2 ///</summary> staticPenp1=newPen(Color.Blue,2); ///<summary> ///绿色宽3 ///</summary> staticPenp2=newPen(Color.Green,3); ///<summary> ///灰色宽1 ///</summary> staticPenp3=newPen(Color.Gray,1); ///<summary> ///微软雅黑 ///</summary> staticFontf1=newFont("微软雅黑",9,FontStyle.Regular); ///<summary> ///圆心X坐标 ///</summary> publicstaticintCenterOfTheCircleX=31; ///<summary> ///圆心Y坐标 ///</summary> publicstaticintCenterOfTheCircleY=46; ///<summary> ///说明条目X坐标 ///</summary> publicstaticintItemStartX=45; ///<summary> ///条目X修正量 ///</summary> publicstaticintItemFixX=-20; ///<summary> ///条目Y修正量 ///</summary> publicstaticintItemFixY=10; publicstaticPointCenterOfThePie=newPoint(CenterOfTheCircleX,CenterOfTheCircleY); ///<summary> ///命中Pie半径 ///</summary> publicstaticintPieRadius=6; ///<summary> ///白点Pie半径 ///</summary> publicstaticintPieRadius2=8; ///<summary> ///圆半径 ///</summary> publicstaticintCircleRadius=9; ///<summary> ///圆心距 ///</summary> publicstaticintCircleSpace=80; ///<summary> ///轴X起点 ///</summary> publicstaticintLineStartX=CenterOfTheCircleX; ///<summary> ///轴Y起点 ///</summary> publicstaticintLineStartY=CenterOfTheCircleY; ///<summary> ///内部Key定义 ///</summary> publicstaticstringKey=""; ///<summary> ///绘图事件 ///</summary> publiceventEventHandler<KeyValueEventArgs>KeyValueChangeEventHandler; publicdelegatevoidLabelClickEventHandler(objectsender,LabelClickEventArgse); //publiceventLabelClickEventHandler<LabelClickEventArgs>; publicdelegatevoidTimeAxisClick(); publicTimeAxisClicklc=null; publicdelegatevoidTimeAxisClick2(stringlabelName); publicTimeAxisClick2lc2=null; ///<summary> ///流程字典 ///</summary> publicstaticSortedDictionary<string,string>sdict=newSortedDictionary<string,string>(); ///<summary> ///水平标示 ///</summary> privatestaticreadonlyintHorizontalTimeAxis=0; ///<summary> ///垂直标志 ///</summary> privatestaticreadonlyintVerticalTimeAxis=1; ///<summary> ///绘制标志,0为水平;1为垂直。 ///</summary> publicstaticintTimeAxisModle=0;
构造方法
#region构造方法 publicuctlTimeAxis() { InitializeComponent(); } publicuctlTimeAxis(SortedDictionary<string,string>s) { InitializeComponent(); if(sdict!=null) { sdict=s; } } publicuctlTimeAxis(SortedDictionary<string,string>s,intmodel) { InitializeComponent(); if(sdict!=null) { sdict=s; TimeAxisModle=model; if(HorizontalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler+=newEventHandler<KeyValueEventArgs>(SetHorizontalStep); } elseif(VerticalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler+=newEventHandler<KeyValueEventArgs>(SetVerticalStep); } } } #endregion
Key值转变
///<summary> ///Key值转变 ///</summary> publicclassKeyValueEventArgs:EventArgs { publicstaticstringKey=""; publicKeyValueEventArgs(strings) { Key=s; } }
以上所述就是本文的全部内容了,希望大家能够喜欢。