当执行长时间后台处理时,你是否希望软件给你一个反馈,让你了解程序执行进度。进度轴帮你忙,轻松掌握全局动态。你的进度你做主!进度轴分为横版和纵版总有一版适合你!
应用了事件机制假如有更好的方法欢迎交流,假如对您有用请顶一下。
载入时间轴控件
////// 载入时间轴控件 /// 2015-04-16 /// 吴海龙 /// public void LoadTimeAxis() { SortedDictionarysdict = new SortedDictionary (); sdict.Add("1", "读取配置"); sdict.Add("2", "选择模板"); sdict.Add("3", "确认数据"); sdict.Add("4", "生成代码"); uta = new uctlTimeAxis(sdict,1); uta.lc = new ToolFunction.uctlTimeAxis.TimeAxisClick(SayHello); CommonFunction.AddForm3(splitContainer4.Panel2, uta); }
panel容器中添加控件
////// 项panel容器中添加控件 /// /// 容器panel /// 显示的usercontrol public static void AddForm3(Panel p, UserControl uc) { p.Controls.Clear(); p.Controls.Add(uc); uc.Dock = DockStyle.Fill; }
初始化纵版界面
////// 初始化垂直进度轴 /// 2015-04-15 /// 吴海龙 /// public void InitVerticalTimeAxis() { try { int TempCenterOfThePieY = CenterOfTheCircleY; using (Graphics g = this.CreateGraphics()) { g.SmoothingMode = SmoothingMode.HighQuality; //使绘图质量最高,即消除锯齿 g.InterpolatiOnMode= InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.DrawString("正在执行:", f1, Brushes.Black, new PointF(CenterOfTheCircleX, 5)); g.DrawLine(p3, new Point(LineStartX, TempCenterOfThePieY), new Point(LineStartX, (sdict.Keys.Count - 1) * CircleSpace + TempCenterOfThePieY)); foreach (var item in sdict.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, new PointF(ItemStartX, TempCenterOfThePieY - ItemFixY)); Label l = new Label(); l.Name = item; l.Location = new Point(ItemStartX,TempCenterOfThePieY - ItemFixY); l.Text = sdict[item]; l.Click +=new EventHandler(l_Click); //l.Click += new EventHandler(l_Click2); this.Controls.Add(l); TempCenterOfThePieY = TempCenterOfThePieY + CircleSpace; } } } catch (Exception exp) { CommonFunction.WriteLog(exp, "绘制失败"); } }
纵版进度轴步进方法
////// 垂直步进方法 /// /// 2015-04-16 /// 吴海龙 /// /// /// public void SetVerticalStep(object sender, KeyValueEventArgs e) { int TempCenterOfThePieY = CenterOfTheCircleY; if ("" == KeyValueEventArgs.Key) { return; } using (Graphics g = this.CreateGraphics()) { g.SmoothingMode = SmoothingMode.HighQuality; //使绘图质量最高,即消除锯齿 g.InterpolatiOnMode= InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; foreach (var item in sdict.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, new Point(LineStartX, LineStartY), new Point(LineStartX, TempCenterOfThePieY)); g.FillEllipse(Brushes.Green, CenterOfTheCircleX - PieRadius, TempCenterOfThePieY - PieRadius, PieRadius * 2, PieRadius * 2); if (item == KeyValueEventArgs.Key) { break; } TempCenterOfThePieY = TempCenterOfThePieY + CircleSpace; } } }
画图属性字段
////// 蓝色宽2 /// static Pen p1 = new Pen(Color.Blue, 2); ////// 绿色宽3 /// static Pen p2 = new Pen(Color.Green, 3); ////// 灰色宽1 /// static Pen p3 = new Pen(Color.Gray, 1); ////// 微软雅黑 /// static Font f1 = new Font("微软雅黑", 9, FontStyle.Regular); ////// 圆心X坐标 /// public static int CenterOfTheCircleX = 31; ////// 圆心Y坐标 /// public static int CenterOfTheCircleY = 46; ////// 说明条目X坐标 /// public static int ItemStartX = 45; ////// 条目X修正量 /// public static int ItemFixX = -20; ////// 条目Y修正量 /// public static int ItemFixY = 10; public static Point CenterOfThePie = new Point(CenterOfTheCircleX, CenterOfTheCircleY); ////// 命中Pie半径 /// public static int PieRadius = 6; ////// 白点Pie半径 /// public static int PieRadius2 = 8; ////// 圆半径 /// public static int CircleRadius = 9; ////// 圆心距 /// public static int CircleSpace = 80; ////// 轴X起点 /// public static int LineStartX = CenterOfTheCircleX; ////// 轴Y起点 /// public static int LineStartY = CenterOfTheCircleY; ////// 内部Key定义 /// public static string Key = ""; ////// 绘图事件 /// public event EventHandlerKeyValueChangeEventHandler; public delegate void LabelClickEventHandler(object sender, LabelClickEventArgs e); //public event LabelClickEventHandler ; public delegate void TimeAxisClick(); public TimeAxisClick lc = null; public delegate void TimeAxisClick2(string labelName); public TimeAxisClick2 lc2 = null; /// /// 流程字典 /// public static SortedDictionarysdict = new SortedDictionary (); /// /// 水平标示 /// private static readonly int HorizOntalTimeAxis= 0; ////// 垂直标志 /// private static readonly int VerticalTimeAxis = 1; ////// 绘制标志,0为水平;1为垂直。 /// public static int TimeAxisModle = 0;
构造方法
#region 构造方法 public uctlTimeAxis() { InitializeComponent(); } public uctlTimeAxis(SortedDictionarys) { InitializeComponent(); if (sdict != null) { sdict = s; } } public uctlTimeAxis(SortedDictionary s, int model) { InitializeComponent(); if (sdict != null) { sdict = s; TimeAxisModle = model; if (HorizOntalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler += new EventHandler (SetHorizontalStep); } else if (VerticalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler += new EventHandler (SetVerticalStep); } } } #endregion
Key值转变
////// Key值转变 /// public class KeyValueEventArgs : EventArgs { public static string Key = ""; public KeyValueEventArgs(string s) { Key = s; } }
以上所述就是本文的全部内容了,希望大家能够喜欢。