基本信息
源码名称:C#自定义步骤条控件
源码大小:0.15M
文件格式:.zip
开发语言:C#
更新时间:2018-06-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍
由于项目需要,需要一个描述流程步骤的控件,于是网上找了相关例子,在做了些修改

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StepBar
{
   [ToolboxBitmap(typeof(StepBar),"title.bmp")]
    public partial class StepBar: UserControl
    {
        public StepBar()
        {
            InitializeComponent();
            this.Height = 68;
        }
        private List<StepEntity> dataSourceList = null;

        /// <summary> 当前步骤
        /// </summary>
        public int CurrentStep { get; set; }

        /// <summary>完成步骤颜色
        /// </summary>
        public Color CompletedColor { get; set; }

        /// <summary>当前步骤颜色
        /// </summary>
        public Color CurrentColor { get; set; }

        /// <summary>为完成步骤颜色
        /// </summary>
        public Color UnCompletedColor { get; set; }

        /// <summary> 步骤线条颜色
        /// </summary>
        public Color LineColor { get; set; }

        /// <summary>
        /// 圆形节点直径
        /// </summary>
        public int StepNodeWidth { get; set; }

        /// <summary>
        /// 字体大小
        /// </summary>
        public Font NFont { get; set; }

        /// <summary>
        /// 序号字体大小
        /// </summary>
        public Font  StepFont { get; set; }
        [Browsable(true), Category("StepBar")]
        public List<StepEntity> ListDataSource
        {
            get
            {
                return dataSourceList;
            }
            set
            {
                if (dataSourceList != value)
                {
                    dataSourceList = value;
                    Invalidate();
                }
            }
        }
        private void StepBar_Paint(object sender, PaintEventArgs e)
        {
            if (this.ListDataSource != null)
            {
                int CenterY = this.Height / 2;
                int index = 1;//执行步骤
                int count = ListDataSource.Count;
                int lineWidth = 1;//120
                int wordWidth = 0;

                //int StepNodeWidth = 28;//圆形点直径

                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                Brush brush = new SolidBrush(Color.Gray);
                Pen p = new Pen(brush, lineWidth);//未完成线条画笔

                Brush brushNode = new SolidBrush(LineColor);//线条画笔
                Pen penNode = new Pen(brushNode, lineWidth);

                Brush brushNodeCompleted = new SolidBrush(CompletedColor);//完成步骤画笔
                Pen penNodeCompleted = new Pen(brushNodeCompleted, lineWidth);

                int initX = 6;
               // Font NFont = new Font("微软雅黑", 12);
                //Font StepFont = new Font("微软雅黑", 11, FontStyle.Bold);

                //计算字体总长度
                foreach (var item in ListDataSource)
                {
                    SizeF sNode = e.Graphics.MeasureString(item.StepName, NFont);
                    wordWidth = (int)Math.Round(sNode.Width);
                }
                lineWidth = (this.Width - StepNodeWidth * count - 12) / (count - 1) - 8;
                int NodeNameWidth = 0;

                foreach (var item in ListDataSource)
                {
                    Rectangle rec = new Rectangle(initX, 6, StepNodeWidth, StepNodeWidth);
                    if (CurrentStep == item.StepOrder)
                    {
                        if (item.StepState == StepEntity.eumStepState.CurrentNow)
                        {
                            e.Graphics.DrawEllipse(new Pen(CurrentColor, 1), rec);
                            e.Graphics.FillEllipse(new SolidBrush(CurrentColor), 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 StepNodeWidth / 2 - (int)Math.Round(fTitle.Width) / 2, 6 (StepNodeWidth / 2 - (int)Math.Round(fTitle.Height / 2)));
                        e.Graphics.DrawString(index.ToString(), StepFont, Brushes.White, pTitle);//绘制步骤序号信息

                        SizeF sNode = e.Graphics.MeasureString(item.StepName, NFont);//计算当前字体长度
                        Point pNode = new Point(initX - (int)(((int)sNode.Width - StepNodeWidth) / 2), 6 StepNodeWidth 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 StepNodeWidth 4, StepNodeWidth / 2 6, initX StepNodeWidth lineWidth, StepNodeWidth / 2 6);
                        }
                    }
                    else if (item.StepOrder < CurrentStep)
                    {
                        e.Graphics.DrawEllipse(penNodeCompleted, rec);
                        e.Graphics.FillEllipse(new SolidBrush(CompletedColor), rec);

                        RectangleF recRF = new RectangleF(rec.X 6, rec.Y 6, rec.Width - 12, rec.Height - 12);
                       // e.Graphics.DrawImage(ControlResource.check_lightblue, recRF);

                        SizeF fTitle = e.Graphics.MeasureString(index.ToString(), StepFont);
                        Point pTitle = new Point(initX StepNodeWidth / 2 - (int)Math.Round(fTitle.Width) / 2, 6 (StepNodeWidth / 2 - (int)Math.Round(fTitle.Height / 2)));
                        e.Graphics.DrawString(index.ToString(), StepFont, Brushes.White, pTitle);//绘制步骤序号信息

                        SizeF sNode = e.Graphics.MeasureString(item.StepName, NFont);
                        Point pNode = new Point(initX - (int)(((int)sNode.Width - StepNodeWidth) / 2), 6 StepNodeWidth 2);
                        e.Graphics.DrawString(item.StepName, NFont, brushNode, pNode);//绘制步骤字体信息
                        NodeNameWidth = (int)Math.Round(sNode.Width);

                        if (index < count)
                        {
                            e.Graphics.DrawLine(p, initX StepNodeWidth 4, StepNodeWidth / 2 6, initX StepNodeWidth lineWidth, StepNodeWidth / 2 6);
                        }
                    }
                    else
                    { 
                         e.Graphics.DrawEllipse(p, rec);
                         //
                         SizeF fTitle = e.Graphics.MeasureString(index.ToString(), StepFont);
                         Point pTitle = new Point(initX StepNodeWidth / 2 - (int)Math.Round(fTitle.Width) / 2, 6 (StepNodeWidth / 2 - (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 - (int)(((int)sNode.Width - StepNodeWidth) / 2), 6 StepNodeWidth 2);
                         e.Graphics.DrawString(item.StepName, NFont, brushNode, pNode);//绘制步骤信息
                         NodeNameWidth = (int)Math.Round(sNode.Width);
                         if (index < count)
                         {
                             //line
                             e.Graphics.DrawLine(p, initX StepNodeWidth 4, StepNodeWidth / 2 6, initX StepNodeWidth lineWidth, StepNodeWidth / 2 6);
                         }
                    }

                    //描述信息
                     if (item.StepDesc != "")
                     {
                         //Point pNode = new Point(initX StepNodeWH, CenterY 3);
                         //e.Graphics.DrawString(item.StepDesc,new Font(nFont.FontFamily,10),brush, pNode);
                     }

                     index ;
                     //8 is space width
                     initX = initX lineWidth StepNodeWidth 8;
                }
            }
        }
    }
}