服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - C# 开发step步骤条控件详解

C# 开发step步骤条控件详解

2021-12-28 16:38JackWang-CUMT C#

本篇文章主要介绍了用C#来实现一个step控件的方法步骤,具有很好的参考价值。下面跟着小编一起来看下吧

现在很多的javascript控件,非常的不错,其中step就是一个,如下图所示:

C# 开发step步骤条控件详解

那么如何用c#来实现一个step控件呢?

先定义一个stepentity类来存储步骤条节点的信息:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class stepentity
 {
  public string id { get; set; }
  public string stepname { get; set; }
  public int steporder { get; set; }
  public eumstepstate stepstate { get; set; }
  public string stepdesc { get; set; }
  public object steptag { get; set; }
  //public image stepcompletedimage { get; set; }
  //public image stepdoingimage { get; set; }
  public stepentity(string id,string stepname,int steporder,string stepdesc, eumstepstate stepstate,object tag)
  {
   this.id = id;
   this.stepname = stepname;
   this.steporder = steporder;
   this.stepdesc = stepdesc;
   this.steptag = tag;
   this.stepstate = stepstate;
  }
 }

定义一个名为stepviewer 的用户控件。

?
1
2
3
4
5
6
7
8
public partial class stepviewer : usercontrol
 {
  public stepviewer()
  {
   initializecomponent();
   this.height = 68;
  }
}

在stepviewer 的用户控件中定义一个listdatasource的属性,如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private list<stepentity> _datasourcelist = null;
  [browsable(true), category("stepviewer")]
  public list<stepentity> listdatasource
  {
   get
   {
    return _datasourcelist;
   }
   set
   {
    if (_datasourcelist != value)
    {
     _datasourcelist = value;
     invalidate();
    }
   }
  }

在此控件的paint方法中,进行步骤条的绘制:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
private void stepviewer_paint(object sender, painteventargs e)
  {
   if(this.listdatasource!=null)
   {
    int centery = this.height / 2;
    int index = 1;
    int count = listdatasource.count;
    int linewidth = 120;
    int stepnodewh = 28;
    //this.width = 32 * count + linewidth * (count - 1) + 6+300;
    //defalut pen & brush
    e.graphics.smoothingmode = system.drawing.drawing2d.smoothingmode.highquality;
    brush brush = new solidbrush(_gray);
    pen p = new pen(brush, 1f);
    brush brushnode = new solidbrush(_darkgray);
    pen pennode = new pen(brushnode, 1f);
    brush brushnodecompleted = new solidbrush(_blue);
    pen pennodecompleted = new pen(brushnodecompleted, 1f);
    int initx = 6;
    //string
    font nfont = new font("微软雅黑", 12);
    font stepfont = new font("微软雅黑", 11,fontstyle.bold);
    int nodenamewidth = 0;
    foreach (var item in listdatasource)
    {
     //round
     rectangle rec = new rectangle(initx, centery - stepnodewh / 2, stepnodewh, stepnodewh);
     if (currentstep == item.steporder)
     {
      if (item.stepstate == eumstepstate.outtime)
      {
       e.graphics.drawellipse(new pen(_red,1f), rec);
       e.graphics.fillellipse(new solidbrush(_red), rec);
      }
      else
      {
       e.graphics.drawellipse(pennodecompleted, rec);
       e.graphics.fillellipse(brushnodecompleted, rec);
      }
      //白色字体
      sizef ftitle = e.graphics.measurestring(index.tostring(), stepfont);
      point ptitle = new point(initx + stepnodewh / 2 - (int)math.round(ftitle.width) / 2, centery - (int)math.round(ftitle.height / 2));
      e.graphics.drawstring(index.tostring(), stepfont, brushes.white, ptitle);
      //nodename
      sizef snode = e.graphics.measurestring(item.stepname, nfont);
      point pnode = new point(initx + stepnodewh, centery - (int)math.round(snode.height / 2) + 2);
      e.graphics.drawstring(item.stepname,new font( nfont,fontstyle.bold), brushnode, pnode);
      nodenamewidth = (int)math.round(snode.width);
      if (index < count)
      {
       e.graphics.drawline(p, initx + stepnodewh + nodenamewidth, centery, initx + stepnodewh + nodenamewidth + linewidth, centery);
      }
     }
     else if (item.steporder < currentstep)
     {
      //completed
      e.graphics.drawellipse(pennodecompleted, rec);
      //image
      rectanglef recrf = new rectanglef(rec.x + 6, rec.y + 6, rec.width - 12, rec.height - 12);
      e.graphics.drawimage(controlsresource.check_lightblue, recrf);
      //nodename
      sizef snode = e.graphics.measurestring(item.stepname, nfont);
      point pnode = new point(initx + stepnodewh, centery - (int)math.round(snode.height / 2) + 2);
      e.graphics.drawstring(item.stepname, nfont, brushnode, pnode);
      nodenamewidth = (int)math.round(snode.width);
      if (index < count)
      {
       e.graphics.drawline(pennodecompleted, initx + stepnodewh + nodenamewidth, centery, initx + stepnodewh + nodenamewidth + linewidth, centery);
      }
     }
     else
     {
      e.graphics.drawellipse(p, rec);
      //
      sizef ftitle = e.graphics.measurestring(index.tostring(), stepfont);
      point ptitle = new point(initx + stepnodewh / 2 - (int)math.round(ftitle.width) / 2, centery - (int)math.round(ftitle.height / 2));
      e.graphics.drawstring(index.tostring(), stepfont, brush, ptitle);
      //nodename
      sizef snode = e.graphics.measurestring(item.stepname, nfont);
      point pnode = new point(initx + stepnodewh, centery - (int)math.round(snode.height / 2) + 2);
      e.graphics.drawstring(item.stepname, nfont, brushnode, pnode);
      nodenamewidth = (int)math.round(snode.width);
      if (index < count)
      {
       //line
       e.graphics.drawline(p, initx + stepnodewh + nodenamewidth, centery, initx + stepnodewh + nodenamewidth + linewidth, centery);
      }
     }
     //描述信息
     if (item.stepdesc != "")
     {
      point pnode = new point(initx + stepnodewh, centery+10);
      e.graphics.drawstring(item.stepdesc,new font(nfont.fontfamily,10),brush, pnode);
     }
     index++;
     //8 is space width
     initx = initx + linewidth + stepnodewh+ nodenamewidth+8;
    }
   }
  }

控件的使用:

?
1
2
3
4
5
6
7
list<stepentity> list = new list<stepentity>();
 list.add(new stepentity("1", "新开单", 1, "这里是该步骤的描述信息", eumstepstate.completed, null));
 list.add(new stepentity("2", "主管审批", 2, "这里是该步骤的描述信息", eumstepstate.waiting, null));
 list.add(new stepentity("3", "总经理审批", 3, "这里是该步骤的描述信息", eumstepstate.outtime, null));
 list.add(new stepentity("2", "完成", 4, "这里是该步骤的描述信息", eumstepstate.waiting, null));
 this.stepviewer1.currentstep = 3;
 this.stepviewer1.listdatasource = list;

C# 开发step步骤条控件详解

同样的,我们可以实现如下的timeline控件。

C# 开发step步骤条控件详解

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持服务器之家!

原文链接:http://www.cnblogs.com/isaboy/p/winform_step_control.html

延伸 · 阅读

精彩推荐
  • C#深入理解C#的数组

    深入理解C#的数组

    本篇文章主要介绍了C#的数组,数组是一种数据结构,详细的介绍了数组的声明和访问等,有兴趣的可以了解一下。...

    佳园9492021-12-10
  • C#SQLite在C#中的安装与操作技巧

    SQLite在C#中的安装与操作技巧

    SQLite,是一款轻型的数据库,用于本地的数据储存。其优点有很多,下面通过本文给大家介绍SQLite在C#中的安装与操作技巧,感兴趣的的朋友参考下吧...

    蓝曈魅11162022-01-20
  • C#如何使用C#将Tensorflow训练的.pb文件用在生产环境详解

    如何使用C#将Tensorflow训练的.pb文件用在生产环境详解

    这篇文章主要给大家介绍了关于如何使用C#将Tensorflow训练的.pb文件用在生产环境的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴...

    bbird201811792022-03-05
  • C#C#微信公众号与订阅号接口开发示例代码

    C#微信公众号与订阅号接口开发示例代码

    这篇文章主要介绍了C#微信公众号与订阅号接口开发示例代码,结合实例形式简单分析了C#针对微信接口的调用与处理技巧,需要的朋友可以参考下...

    smartsmile20127762021-11-25
  • C#VS2012 程序打包部署图文详解

    VS2012 程序打包部署图文详解

    VS2012虽然没有集成打包工具,但它为我们提供了下载的端口,需要我们手动安装一个插件InstallShield。网上有很多第三方的打包工具,但为什么偏要使用微软...

    张信秀7712021-12-15
  • C#C#设计模式之Strategy策略模式解决007大破密码危机问题示例

    C#设计模式之Strategy策略模式解决007大破密码危机问题示例

    这篇文章主要介绍了C#设计模式之Strategy策略模式解决007大破密码危机问题,简单描述了策略模式的定义并结合加密解密算法实例分析了C#策略模式的具体使用...

    GhostRider10972022-01-21
  • C#利用C#实现网络爬虫

    利用C#实现网络爬虫

    这篇文章主要介绍了利用C#实现网络爬虫,完整的介绍了C#实现网络爬虫详细过程,感兴趣的小伙伴们可以参考一下...

    C#教程网11852021-11-16
  • C#三十分钟快速掌握C# 6.0知识点

    三十分钟快速掌握C# 6.0知识点

    这篇文章主要介绍了C# 6.0的相关知识点,文中介绍的非常详细,通过这篇文字可以让大家在三十分钟内快速的掌握C# 6.0,需要的朋友可以参考借鉴,下面来...

    雨夜潇湘8272021-12-28