C#开发step步骤条控件的代码详解(图)

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

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

C#开发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 = 68;  }}

登录后复制

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

private List _dataSourceList = null;  [Browsable(true), Category("StepViewer")]  public List 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 / 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 

控件的使用:

List list = new List(); 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步骤条控件的代码详解(图)

以上就是C#开发step步骤条控件的代码详解(图)的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2495558.html

(0)
上一篇 2025年3月5日 02:19:11
下一篇 2025年2月25日 02:52:12

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • C#基础入门-关键字的介绍

    本文主要介绍了c# 基础知识–关键字的相关知识,具有很好的参考价值,下面跟着小编一起来看下吧 例子: using System;using System.Collections.Generic;using System.Text…

    编程技术 2025年3月5日
    200
  • C#基础入门-简单了解注释

    本文主要介绍了c#中注释的相关知识,具有很好的参考价值,下面跟着小编一起来看下吧 注释,是代码中的一些“说明性文字”。注释本身不会参与程序的编译和运行,仅仅供程序员阅读。 注释分为:单行注释、多行注释、文档注释。 单行注释的符号是2条斜线“…

    编程技术 2025年3月5日
    200
  • 详细介绍C#中new的几种用法

    本文主要介绍了c#中new的几种用法,具有很好的参考价值,下面跟着小编一起来看下吧 在 C# 中,new 关键字可用作运算符、修饰符或约束。 new 运算符 用于创建对象和调用构造函数。 new 修饰符 用于向基类成员隐藏继承成员。 new…

    编程技术 2025年3月5日
    200
  • C#生成漂亮验证码的完整示例代码分享

    本文主要介绍了c#生成漂亮验证码的完整代码类。具有很好的参考价值。下面跟着小编一起来看下吧 话不多说,请看代码: using System;using System.Web;using System.Drawing;using System…

    编程技术 2025年3月5日
    200
  • 详解C#获取本机IP地址(ipv4)的代码案例

    本文主要介绍了c#获取本机所有ip地址的方法、c#获取本机ip地址(ipv4)的方法等。具有很好的参考价值。下面跟着小编一起来看下吧 获取本机所有IP地址: 这些地址是包含所有网卡(虚拟网卡)的ipv4和ipv6地址。  string na…

    编程技术 2025年3月5日
    200
  • C#构建分页应用的实例方法分析

    这篇文章主要介绍了c#构建分页应用的方法,结合实例形式分析了c#创建分页功能的具体步骤与相关实现技巧,需要的朋友可以参考下 本文实例讲述了C#构建分页应用的方法。分享给大家供大家参考,具体如下: 1、SQL语句 WITH [temptabl…

    编程技术 2025年3月5日
    200
  • C#中@用法的实例解析

    本文实例汇总了c#中@的用法,对c#程序设计来说有不错的借鉴价值。具体如下: 一 字符串中的用法 1.学过C#的人都知道C# 中字符串常量可以以@ 开头声名,这样的优点是转义序列“不”被处理,按“原样”输出,即我们不需要对转义字符加上 (反…

    编程技术 2025年3月5日
    200
  • C#中载入界面的经典实例

    这篇文章主要介绍了c#中载入界面的常用方法,涉及窗体的操作,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C#中载入界面的常用方法。分享给大家供大家参考。具体方法分析如下: 方法1.采用事件委托的方法  对象:主窗体:FrmMain…

    编程技术 2025年3月5日
    200
  • 介绍一款C#中可携带附加消息的增强消息框(MessageBoxEx)

    一个可携带附加消息的增强消息框messageboxex分享给大家,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 ————–201507160917更新—&#8212…

    2025年3月5日 编程技术
    200
  • GridView在C#中导出Excel的方法实例

    本篇文章主要介绍了c#实现gridview导出excel实例代码,这里整理了详细的代码,非常具有实用价值,需要的朋友可以参考下。 using System.Data;using System.Web;using System.Web.UI;…

    编程技术 2025年3月5日
    200

发表回复

登录后才能评论