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

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

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

     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 的用户控件。

 public partial class StepViewer : UserControl
{
public StepViewer()
{
InitializeComponent();
this.Height = ;
}
}

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

   private List<StepEntity> _dataSourceList = null;
[Browsable(true), Category("StepViewer")]
public List<StepEntity> ListDataSource
{
get
{
return _dataSourceList;
}
set
{
if (_dataSourceList != value)
{
_dataSourceList = value;
Invalidate();
}
}
}

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

  private void StepViewer_Paint(object sender, PaintEventArgs e)
{
if(this.ListDataSource!=null)
{
int CenterY = this.Height / ;
int index = ;
int count = ListDataSource.Count;
int lineWidth = ;
int StepNodeWH = ;
//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 = ;
//string
Font nFont = new Font("微软雅黑", );
Font stepFont = new Font("微软雅黑", ,FontStyle.Bold);
int NodeNameWidth = ; foreach (var item in ListDataSource)
{ //round Rectangle rec = new Rectangle(initX, CenterY - StepNodeWH / , 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 / - (int)Math.Round(fTitle.Width) / , CenterY - (int)Math.Round(fTitle.Height / ));
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 / ) + ); 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 + , rec.Y + , rec.Width - , rec.Height - );
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 / ) + );
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 / - (int)Math.Round(fTitle.Width) / , CenterY - (int)Math.Round(fTitle.Height / ));
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 / ) + );
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+);
e.Graphics.DrawString(item.StepDesc,new Font(nFont.FontFamily,),brush, pNode);
} index++;
//8 is space width
initX = initX + lineWidth + StepNodeWH+ NodeNameWidth+;
}
}
}

控件的使用:

  List<StepEntity> list = new List<StepEntity>();
list.Add(new StepEntity("", "新开单", , "这里是该步骤的描述信息", eumStepState.Completed, null)); list.Add(new StepEntity("", "主管审批", , "这里是该步骤的描述信息", eumStepState.Waiting, null));
list.Add(new StepEntity("", "总经理审批", , "这里是该步骤的描述信息", eumStepState.OutTime, null));
list.Add(new StepEntity("", "完成", , "这里是该步骤的描述信息", eumStepState.Waiting, null)); this.stepViewer1.CurrentStep = ;
this.stepViewer1.ListDataSource = list;

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

C#开发step步骤条控件的更多相关文章

  1. WPF教程002 - 实现Step步骤条控件

    原文:WPF教程002 - 实现Step步骤条控件 在网上看到这么一个效果,刚好在用WPF做控件,就想着用WPF来实现一下 1.实现原理 1.1.该控件分为2个模块,类似ComboBox控件分为Ste ...

  2. WPF-自定义实现步骤条控件

    步骤条实现的效果: 步骤条控件是在listbox的基础上实现的. 一. xaml代码: <Window.Resources> <convert1:StepListBarWidthCo ...

  3. iOS开发UI篇—UIScrollView控件实现图片缩放功能

    iOS开发UI篇—UIScrollView控件实现图片缩放功能 一.缩放 1.简单说明: 有些时候,我们可能要对某些内容进行手势缩放,如下图所示 UIScrollView不仅能滚动显示大量内容,还能对 ...

  4. EBS OAF 开发中的OAMessageRadioGroup控件

    EBS OAF 开发中的OAMessageRadioGroup控件 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 简单介绍 RadioGro ...

  5. SNF开发平台WinForm-Grid表格控件大全

    我们在开发系统时,会有很多种控件进行展示,甚至有一些为了方便的一些特殊需求. 那么下面就介绍一些我们在表格控件里常用的方便的控件:   1.Grid表格查询条 Grid表格下拉 3.Grid表格弹框选 ...

  6. Photoshop和WPF双剑配合,打造炫酷个性的进度条控件

    现在如果想打造一款专业的App,UI的设计和操作的简便性相当重要.UI设计可以借助Photoshop或者AI等设计工具,之前了解到WPF设计工具Expression Blend可以直接导入PSD文件或 ...

  7. iOS开发UI篇—UIScrollView控件介绍

    iOS开发UI篇—UIScrollView控件介绍 一.知识点简单介绍 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤大⼩小是极其有限的,因此直接展⽰示在⽤用户眼前的内容也相当有限 ...

  8. iOS开发UI篇—UITableview控件使用小结

    iOS开发UI篇—UITableview控件使用小结 一.UITableview的使用步骤 UITableview的使用就只有简单的三个步骤: 1.告诉一共有多少组数据 方法:- (NSInteger ...

  9. iOS开发UI篇—UIScrollView控件实现图片轮播

    iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播            二.实现代码 storyboard中布局 代码: #import "YYV ...

随机推荐

  1. 让VLC也拥有斷點播放功能

    如何让VLC也拥有记忆功能,记住上次播放位置.以下都是在Windows系统下操作,其他 方法/步骤 下载 libsrpos_plugin-0.5.win 插件 https://sourceforge. ...

  2. zabbix3.0.4 部署History

    [root@zabbix-Test ~]# history     1  passwd root    2  exit    3  yum  install ntpd*    4  yum  inst ...

  3. 在asp.net中使用ajax记录

    一.问题描述 ajax在mvc中使用频繁,比如cms中的评论功能,但由于涉及到前后端开发,日久容易忘,在此做下记录. 二.内容 控制器中代码示例: /// <summary> /// 在文 ...

  4. 3. 托管对象模型的迁移(Core Data 应用程序实践指南)

    本章介绍如何添加模型版本及模型映射,演示几种迁移技术,供在升级模型时使用. 3.1. 修改托管对象模型 3.2. 添加模型版本 3.3. 轻量级迁移方式 3.4. 默认的迁移方式 3.5. 通过迁移管 ...

  5. JDBC连接SQL Server 2005步骤详解

    一.设置SQL Server服务器:    1.“开始” → “程序” → “Microsoft SQL Server 2005” → “配置工具” → “SQL Server Configurati ...

  6. html代替submit按钮的图片代码

    代替submit按钮的图片代码格式是 <input type="image" name="..." src="..." onClick ...

  7. Unity3D 相关技术

    slua相关shader编程相关animation相关attack check攻击检测相关

  8. CSS 文本、字体、链接

    CSS 文本属性可定义文本的外观. 通过文本属性,您可以改变文本的颜色.字符间距,对齐文本,装饰文本,对文本进行缩进,等等. 缩进文本 把 Web 页面上的段落的第一行缩进,这是一种最常用的文本格式化 ...

  9. BootstrapTable(附源码) Bootstrap结合BootstrapTable的使用,分为两种模试显示列表。

    引用的css: <link href="@Url.Content("~/Css/bootstrap.min.css")" rel="styles ...

  10. SQL Server 手把手教你使用profile进行性能监控

    200 ? "200px" : this.width)!important;} --> 介绍 经常会有人问profile工具该怎么使用?有没有方法获取性能差的sql的问题.自 ...