在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#图形和图像处理 → C#自定义步骤条控件

C#自定义步骤条控件

C#图形和图像处理

下载此实例
  • 开发语言:C#
  • 实例大小:0.15M
  • 下载次数:140
  • 浏览次数:1603
  • 发布时间:2018-06-05
  • 实例类别:C#图形和图像处理
  • 发 布 人:明天过后还是明天
  • 文件格式:.zip
  • 所需积分:5
 相关标签: C# 控件 自定义 步骤条

实例介绍

【实例简介】由于项目需要,需要一个描述流程步骤的控件,于是网上找了相关例子,在做了些修改
【实例截图】

【核心代码】

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;
                }
            }
        }
    }
}


实例下载地址

C#自定义步骤条控件

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警