C# · 12月 28, 2021

C#进度轴控件分享

当执行长时间后台处理时,你是否希望软件给你一个反馈,让你了解程序执行进度。进度轴帮你忙,轻松掌握全局动态。你的进度你做主!进度轴分为横版和纵版总有一版适合你!

应用了事件机制假如有更好的方法欢迎交流,假如对您有用请顶一下。

载入时间轴控件

/// <summary> /// 载入时间轴控件 /// 2015-04-16 /// 吴海龙 /// </summary> public void LoadTimeAxis() { SortedDictionary<string,string> sdict = new SortedDictionary<string,string>(); 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容器中添加控件

/// <summary> /// 项panel容器中添加控件 /// </summary> /// <param name=”p”>容器panel</param> /// <param name=”uc”>显示的usercontrol</param> public static void AddForm3(Panel p,UserControl uc) { p.Controls.Clear(); p.Controls.Add(uc); uc.Dock = DockStyle.Fill; }

初始化纵版界面

/// <summary> /// 初始化垂直进度轴 /// 2015-04-15 /// 吴海龙 /// </summary> 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),(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],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,”绘制失败”); }}

纵版进度轴步进方法

/// <summary> /// 垂直步进方法 /// /// 2015-04-16 /// 吴海龙 /// </summary> /// <param name=”sender”></param> /// <param name=”e”></param> 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],Brushes.Green,ItemStartX,TempCenterOfThePieY – ItemFixY); g.DrawEllipse(Pens.Green,CircleRadius * 2); g.DrawLine(p2,LineStartY),TempCenterOfThePieY)); g.FillEllipse(Brushes.Green,CenterOfTheCircleX – PieRadius,TempCenterOfThePieY – PieRadius,PieRadius * 2,PieRadius * 2); if (item == KeyValueEventArgs.Key) { break; } TempCenterOfThePieY = TempCenterOfThePieY + CircleSpace; } }}

画图属性字段

/// <summary> /// 蓝色宽2 /// </summary> static Pen p1 = new Pen(Color.Blue,2); /// <summary> /// 绿色宽3 /// </summary> static Pen p2 = new Pen(Color.Green,3); /// <summary> /// 灰色宽1 /// </summary> static Pen p3 = new Pen(Color.Gray,1); /// <summary> /// 微软雅黑 /// </summary> static Font f1 = new Font(“微软雅黑”,9,FontStyle.Regular); /// <summary> /// 圆心X坐标 /// </summary> public static int CenterOfTheCircleX = 31; /// <summary> /// 圆心Y坐标 /// </summary> public static int CenterOfTheCircleY = 46; /// <summary> /// 说明条目X坐标 /// </summary> public static int ItemStartX = 45; /// <summary> /// 条目X修正量 /// </summary> public static int ItemFixX = -20; /// <summary> /// 条目Y修正量 /// </summary> public static int ItemFixY = 10; public static Point CenterOfThePie = new Point(CenterOfTheCircleX,CenterOfTheCircleY); /// <summary> /// 命中Pie半径 /// </summary> public static int PieRadius = 6; /// <summary> /// 白点Pie半径 /// </summary> public static int PieRadius2 = 8; /// <summary> /// 圆半径 /// </summary> public static int CircleRadius = 9; /// <summary> /// 圆心距 /// </summary> public static int CircleSpace = 80; /// <summary> /// 轴X起点 /// </summary> public static int LineStartX = CenterOfTheCircleX; /// <summary> /// 轴Y起点 /// </summary> public static int LineStartY = CenterOfTheCircleY; /// <summary> /// 内部Key定义 /// </summary> public static string Key = “”; /// <summary> /// 绘图事件 /// </summary> public event EventHandler<KeyValueEventArgs> KeyValueChangeEventHandler; public delegate void LabelClickEventHandler(object sender,LabelClickEventArgs e); //public event LabelClickEventHandler<LabelClickEventArgs> ; public delegate void TimeAxisClick(); public TimeAxisClick lc = null; public delegate void TimeAxisClick2(string labelName); public TimeAxisClick2 lc2 = null; /// <summary> /// 流程字典 /// </summary> public static SortedDictionary<string,string>(); /// <summary> /// 水平标示 /// </summary> private static readonly int HorizontalTimeAxis = 0; /// <summary> /// 垂直标志 /// </summary> private static readonly int VerticalTimeAxis = 1; /// <summary> /// 绘制标志,0为水平;1为垂直。 /// </summary> public static int TimeAxisModle = 0;

构造方法

#region 构造方法 public uctlTimeAxis() { InitializeComponent(); } public uctlTimeAxis(SortedDictionary<string,string> s) { InitializeComponent(); if (sdict != null) { sdict = s; } } public uctlTimeAxis(SortedDictionary<string,string> s,int model) { InitializeComponent(); if (sdict != null) { sdict = s; TimeAxisModle = model; if (HorizontalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler += new EventHandler<KeyValueEventArgs>(SetHorizontalStep); } else if (VerticalTimeAxis==TimeAxisModle) { KeyValueChangeEventHandler += new EventHandler<KeyValueEventArgs>(SetVerticalStep); } } }#endregion

Key值转变

/// <summary> /// Key值转变 /// </summary> public class KeyValueEventArgs : EventArgs { public static string Key = “”; public KeyValueEventArgs(string s) { Key = s; } }

以上所述就是本文的全部内容了,希望大家能够喜欢。