欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#进度轴控件分享

程序员文章站 2023-10-27 08:53:16
当执行长时间后台处理时,你是否希望软件给你一个反馈,让你了解程序执行进度。进度轴帮你忙,轻松掌握全局动态。你的进度你做主!进度轴分为横版和纵版总有一版适合你! 应用了事件...

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

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

载入时间轴控件

/// <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), 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, "绘制失败");
      }
}

纵版进度轴步进方法

/// <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], 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;
        }
      }
}

画图属性字段

/// <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> sdict = new 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;
     }
   }

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