C#制作甘特图

     先自制甘特图控件:

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.ComponentModel;

namespace GanttControls
{

    /// <summary>  
    /// 甘特图控件  
    /// zgke@sina.com  
    /// qq:116149  
    /// </summary>  
    public class ProjectViewBox : UserControl
    {
        #region 容器
        #region 设计器代码
        /// <summary>   
        /// 必需的设计器变量。  
        /// </summary>  
        private System.ComponentModel.IContainer components = null;

        /// <summary>   
        /// 清理所有正在使用的资源。  
        /// </summary>  
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>  
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region 组件设计器生成的代码

        /// <summary>   
        /// 设计器支持所需的方法 - 不要  
        /// 使用代码编辑器修改此方法的内容。  
        /// </summary>  
        private void InitializeComponent()
        {
            this.hScrollBar1 = new System.Windows.Forms.HScrollBar();
            this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
            this.MainPictureBox = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.MainPictureBox)).BeginInit();
            this.SuspendLayout();
            //   
            // hScrollBar1  
            //   
            this.hScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.hScrollBar1.LargeChange = 1;
            this.hScrollBar1.Location = new System.Drawing.Point(1, 111);
            this.hScrollBar1.Maximum = 60;
            this.hScrollBar1.Name = "hScrollBar1";
            this.hScrollBar1.Size = new System.Drawing.Size(120, 16);
            this.hScrollBar1.TabIndex = 0;
            //   
            // vScrollBar1  
            //   
            this.vScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.vScrollBar1.LargeChange = 1;
            this.vScrollBar1.Location = new System.Drawing.Point(121, 0);
            this.vScrollBar1.Maximum = 60;
            this.vScrollBar1.Name = "vScrollBar1";
            this.vScrollBar1.Size = new System.Drawing.Size(16, 111);
            this.vScrollBar1.TabIndex = 1;
            //   
            // MainPictureBox  
            //   
            this.MainPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.MainPictureBox.Location = new System.Drawing.Point(0, 0);
            this.MainPictureBox.Name = "MainPictureBox";
            this.MainPictureBox.Size = new System.Drawing.Size(120, 109);
            this.MainPictureBox.TabIndex = 2;
            this.MainPictureBox.TabStop = false;
            //   
            // ProjectBox  
            //   
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Control;
            this.Controls.Add(this.vScrollBar1);
            this.Controls.Add(this.hScrollBar1);
            this.Controls.Add(this.MainPictureBox);
            this.Name = "ProjectBox";
            this.Size = new System.Drawing.Size(139, 129);
            this.Load += new System.EventHandler(this.ProjectBox_Load);
            this.SizeChanged += new System.EventHandler(this.ProjectBox_SizeChanged);
            ((System.ComponentModel.ISupportInitialize)(this.MainPictureBox)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.HScrollBar hScrollBar1;
        private System.Windows.Forms.VScrollBar vScrollBar1;
        private System.Windows.Forms.PictureBox MainPictureBox;
        #endregion

        public ProjectViewBox()
        {
            InitializeComponent();
        }

        #region 私有成员
        /// <summary>  
        /// 最小单元格  
        /// </summary>  
        private int m_Size = 18;
        /// <summary>  
        /// 日期索引 记录当前绘制的位置  
        /// </summary>  
        private int m_DayIndex = 0;
        /// <summary>  
        /// 开始绘制位置  
        /// </summary>  
        private int m_JobIndex = 0;
        #endregion

        /// <summary>  
        /// 大小改变  
        /// </summary>  
        /// <param name="sender"></param>  
        /// <param name="e"></param>  
        private void ProjectBox_SizeChanged(object sender, EventArgs e)
        {
            if (MainPictureBox.Image != null) PaintProjectImage();
        }

        private MyScroll Hscroll;
        private MyScroll Vscroll;

        private void ProjectBox_Load(object sender, EventArgs e)
        {
            MainPictureBox.Image = new Bitmap(1, 1);
            PaintProjectImage();
            Hscroll = new MyScroll();
            Hscroll.Click += new MyScroll.ScrollClick(Hscroll_Click);
            Hscroll.AssignHandle(hScrollBar1.Handle);

            Vscroll = new MyScroll();
            Vscroll.Click += new MyScroll.ScrollClick(Vscroll_Click);
            Vscroll.AssignHandle(vScrollBar1.Handle);

            m_ProjectSelect.ProjectBox = this;
        }

        #region 滚动条
        void Vscroll_Click(int p_Value)
        {
            switch (p_Value)
            {
                case 0:
                    m_JobIndex = vScrollBar1.Value;
                    break;
                case 1:
                    m_JobIndex--;
                    if (m_JobIndex < 0) m_JobIndex = 0;
                    break;
                case 2:
                    m_JobIndex++;
                    break;

            }
            if (m_JobIndex <= 0) vScrollBar1.Value = 0;
            if (m_JobIndex >= 60) vScrollBar1.Value = 60;
            PaintProjectImage();
        }

        void Hscroll_Click(int p_Value)
        {
            switch (p_Value)
            {
                case 0:
                    m_DayIndex = hScrollBar1.Value;
                    break;
                case 1:
                    m_DayIndex--;
                    break;
                case 2:
                    m_DayIndex++;
                    break;

            }
            if (m_DayIndex <= 0) hScrollBar1.Value = 0;
            if (m_DayIndex >= 60) hScrollBar1.Value = 60;
            PaintProjectImage();
        }
        #endregion

        /// <summary>  
        /// 刷新  
        /// </summary>  
        public override void Refresh()
        {
            PaintProjectImage();
        }

        /// <summary>  
        /// 开始绘制  
        /// </summary>  
        private void PaintProjectImage()
        {
            MainPictureBox.Image.Dispose();
            if (MainPictureBox.Width == 0 || MainPictureBox.Height == 0) return;
            Bitmap _NewBitmap = new Bitmap(MainPictureBox.Width, MainPictureBox.Height);
            Graphics _Graphics = Graphics.FromImage(_NewBitmap);
            Point _DrawPoint = new Point(0, 0);
            DateTime _DrawDate = DateTime.Now.AddDays(m_DayIndex);
            while (true)
            {
                _DrawPoint = GraphicsWeekHead(_Graphics, ref _DrawDate, _DrawPoint);

                if (_DrawPoint.X > MainPictureBox.Width) break;
            }

            DateTime _NodeStarDate = DateTime.Now.AddDays(m_DayIndex);
            int _Hight = m_Size * 2;
            for (int i = m_JobIndex; i < m_ProjectSelect.Count; i++)
            {
                m_ProjectSelect[i].GraphisDraw(_Graphics, _NodeStarDate, m_Size, ref _Hight, MainPictureBox.Width, MainPictureBox.Height);
            }

            MainPictureBox.Image = _NewBitmap;
        }

        /// <summary>  
        /// 绘制日期头和星期几  
        /// </summary>  
        /// <param name="p_Graphics">刷子</param>  
        /// <param name="p_StarDate">开始日期 ref类型 返回日期的下周一</param>  
        /// <param name="p_StarPoint">开始位置</param>  
        /// <returns>结束节点</returns>  
        private Point GraphicsWeekHead(Graphics p_Graphics, ref DateTime p_StarDate, Point p_StarPoint)
        {
            int _Date = (int)p_StarDate.DayOfWeek;
            if (_Date != 0) p_StarDate = p_StarDate.AddDays(-_Date);
            int _DrawDateX = p_StarPoint.X - (_Date * m_Size);
            Pen _LinePen = new Pen(Brushes.Black, 1);
            Rectangle _RectangleHead = new Rectangle(_DrawDateX, 0, m_Size * 7, m_Size);
            StringFormat _StringFormat = new StringFormat();
            _StringFormat.LineAlignment = StringAlignment.Far;

            p_Graphics.DrawRectangle(_LinePen, _RectangleHead);
            p_Graphics.DrawString(p_StarDate.ToString("yyyy年MM月dd日"), this.Font, Brushes.Black, _RectangleHead, _StringFormat);

            _RectangleHead = new Rectangle(p_StarPoint.X, m_Size, p_StarPoint.X + m_Size, m_Size);
            Rectangle _BlackRect = new Rectangle(0, m_Size * 2, m_Size, this.Height - (m_Size * 2));

            Color _BlackColor = m_ProjectSelect.BackColor;

            for (int i = _Date; i != 7; i++)
            {
                string _WeekText = string.Empty;
                switch (i)
                {
                    case 0:
                        _WeekText = "日";
                        _BlackColor = m_ProjectSelect.WeekBackColor;
                        break;
                    case 1:
                        _WeekText = "一";
                        _BlackColor = m_ProjectSelect.BackColor;
                        break;
                    case 2:
                        _WeekText = "二";
                        _BlackColor = m_ProjectSelect.BackColor;
                        break;
                    case 3:
                        _WeekText = "三";
                        _BlackColor = m_ProjectSelect.BackColor;
                        break;
                    case 4:
                        _WeekText = "四";
                        _BlackColor = m_ProjectSelect.BackColor;
                        break;
                    case 5:
                        _WeekText = "五";
                        _BlackColor = m_ProjectSelect.BackColor;
                        break;
                    case 6:
                        _WeekText = "六";
                        _BlackColor = m_ProjectSelect.WeekBackColor;
                        break;
                }
                HatchBrush _BlackBrush = new HatchBrush(HatchStyle.Percent50, _BlackColor, Color.White);
                _BlackRect.X = _RectangleHead.X;
                p_Graphics.FillRectangle(_BlackBrush, _BlackRect);

                p_Graphics.DrawRectangle(_LinePen, _RectangleHead);
                p_Graphics.DrawString(_WeekText, new Font("宋体", 9.0f), GetWorkColumneColor(p_StarDate, i), _RectangleHead, _StringFormat);
                _RectangleHead.X += m_Size;
            }
            p_StarDate = p_StarDate.AddDays(7);
            return new Point(_RectangleHead.X, m_Size * 2);
        }

        /// <summary>  
        /// 获取日期的标题色  
        /// </summary>  
        /// <param name="p_Date">日期</param>  
        /// <param name="p_Day">1-7</param>  
        /// <returns></returns>  
        public SolidBrush GetWorkColumneColor(DateTime p_Date, int p_Day)
        {
            DateTime _ValueDate = p_Date.AddDays(p_Day);

            if (_ValueDate.DayOfWeek == DayOfWeek.Saturday && !m_ProjectSelect.SaturdayOfWork)
            {
                return new SolidBrush(m_ProjectSelect.ColumnHolidayColor);
            }
            if (_ValueDate.DayOfWeek == DayOfWeek.Sunday && !m_ProjectSelect.SundayOfWork)
            {
                return new SolidBrush(m_ProjectSelect.ColumnHolidayColor);
            }

            for (int z = 0; z != m_ProjectSelect.HolidayList.Count; z++)
            {
                bool _Year = m_ProjectSelect.HolidayList[z].Year == _ValueDate.Year;
                bool _Month = m_ProjectSelect.HolidayList[z].Month == _ValueDate.Month;
                bool _Day = m_ProjectSelect.HolidayList[z].Day == _ValueDate.Day;

                if (_Year && _Month && _Day)
                {
                    return new SolidBrush(m_ProjectSelect.ColumnHolidayColor);
                }
            }

            return new SolidBrush(m_ProjectSelect.ColumnWorkDayColor);
        }

        #region 公用属性
        private ProjectSelect m_ProjectSelect = new ProjectSelect();
        /// <summary>  
        /// 基本设置  
        /// </summary>       
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public ProjectSelect ProjectSelectData
        {
            get { return m_ProjectSelect; }
            set { m_ProjectSelect = value; m_ProjectSelect.ProjectBox = this; }
        }
        #endregion

        /// <summary>  
        /// 实在写不好Scroll 判断消息了  
        /// </summary>  
        private class MyScroll : NativeWindow
        {
            public delegate void ScrollClick(int p_Value);
            public event ScrollClick Click;

            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                int _ClickType = -1;
                switch (m.Msg)
                {
                    case 0xEa:
                        _ClickType = 0;
                        break;
                    case 0x2114:
                        switch (m.WParam.ToInt32())
                        {
                            case 0:
                                _ClickType = 1;
                                break;
                            case 1:
                                _ClickType = 2;
                                break;
                            case 3:
                                _ClickType = 0;
                                break;
                            case 2:
                                _ClickType = 0;
                                break;
                        }
                        break;
                    case 0x2115:
                        switch (m.WParam.ToInt32())
                        {
                            case 0:
                                _ClickType = 1;
                                break;
                            case 1:
                                _ClickType = 2;
                                break;
                            case 3:
                                _ClickType = 0;
                                break;
                            case 2:
                                _ClickType = 0;
                                break;
                        }
                        break;
                    default:
                        break;
                }
                if (Click != null && _ClickType != -1) Click(_ClickType);

            }
        }
        #endregion

        /// <summary>  
        /// 数据类  
        /// </summary>  
        [Serializable]
        public class ProjectSelect
        {
            private IList<DateTime> m_HolidayList = new List<DateTime>();
            private bool m_SundayOfWork = false;
            private bool m_SaturdayOfWork = false;
            private ProjectViewBox m_ProjectBox;
            private Color m_BackColor = Color.White;
            private Color m_WeekBackColor = Color.FromArgb(255, 212, 208, 200);
            private IList<ProjectNode> m_Nodes = new List<ProjectNode>();
            private Color m_ColumnWorkDayColor = Color.Black;
            private Color m_ColumnHolidayColor = Color.Red;


            public ProjectNode this[int p_Index]
            {
                get
                {
                    return m_Nodes[p_Index];
                }
            }

            /// <summary>  
            /// 工作日背景颜色  
            /// </summary>  
            public Color BackColor { get { return m_BackColor; } set { m_BackColor = value; } }
            /// <summary>  
            /// 假期颜色  
            /// </summary>  
            public Color WeekBackColor { get { return m_WeekBackColor; } set { m_WeekBackColor = value; } }
            /// <summary>  
            /// 星期六是否工作 false为放假  
            /// </summary>  
            public bool SaturdayOfWork { get { return m_SaturdayOfWork; } set { m_SaturdayOfWork = value; } }
            /// <summary>  
            /// 星期日是否工作 false为放假  
            /// </summary>  
            public bool SundayOfWork { get { return m_SundayOfWork; } set { m_SundayOfWork = value; } }
            /// <summary>  
            /// 假期设置  
            /// </summary>  
            public IList<DateTime> HolidayList { get { return m_HolidayList; } set { m_HolidayList = value; } }
            /// <summary>  
            /// 该设置的显示控件  
            /// </summary>  
            public ProjectViewBox ProjectBox { get { return m_ProjectBox; } set { m_ProjectBox = value; } }
            /// <summary>  
            /// 数量  
            /// </summary>  
            public int Count { get { return m_Nodes.Count; } }
            /// <summary>  
            /// 假期颜色(标题)  
            /// </summary>  
            public Color ColumnHolidayColor { get { return m_ColumnHolidayColor; } set { m_ColumnHolidayColor = value; } }
            /// <summary>  
            /// 工作日颜色(标题)  
            /// </summary>  
            public Color ColumnWorkDayColor { get { return m_ColumnWorkDayColor; } set { m_ColumnWorkDayColor = value; } }


            /// <summary>  
            /// 添加  
            /// </summary>  
            /// <param name="p_NodeList">内容</param>  
            public void Add(ProjectNode p_NodeList)
            {
                p_NodeList.ProjectSelect = this;
                m_Nodes.Add(p_NodeList);
                Refresh();
            }
            /// <summary>  
            /// 清除  
            /// </summary>  
            public void Clear()
            {
                m_Nodes.Clear();
                Refresh();
            }
            /// <summary>  
            /// 插入  
            /// </summary>  
            /// <param name="p_Index"></param>  
            /// <param name="p_NodeList"></param>  
            public void Insert(int p_Index, ProjectNode p_NodeList)
            {
                m_Nodes.Insert(p_Index, p_NodeList);
                Refresh();
            }
            /// <summary>  
            /// 删除  
            /// </summary>  
            /// <param name="p_Index"></param>  
            public void RemoveAt(int p_Index)
            {
                m_Nodes.RemoveAt(p_Index);
                Refresh();
            }
            /// <summary>  
            /// 删除  
            /// </summary>  
            /// <param name="p_NodeList"></param>  
            public void Remove(ProjectNode p_NodeList)
            {
                m_Nodes.Remove(p_NodeList);
                Refresh();
            }
            /// <summary>  
            /// 刷新  
            /// </summary>  
            public void Refresh()
            {
                m_ProjectBox.Refresh();
            }


        }

        /// <summary>  
        /// 节点类  
        /// </summary>  
        [Serializable]
        public class ProjectNode
        {
            private string m_JobName = string.Empty;
            private sbyte m_Complete = -1;
            private DateTime m_StartDate = DateTime.Now;
            private uint m_WorkDay = 0;
            private HatchStyle m_Style = HatchStyle.Percent50;
            private Color m_Color = Color.Blue;
            private ProjectSelect m_ProjectSelect;

            public ProjectNode(DateTime p_StarTime, uint p_WorkDay)
            {
                m_StartDate = p_StarTime;
                m_WorkDay = p_WorkDay;
            }

            public ProjectNode(DateTime p_StarTime, uint p_WorkDay, string p_JobName)
            {
                m_StartDate = p_StarTime;
                m_WorkDay = p_WorkDay;
                m_JobName = p_JobName;
            }

            /// <summary>  
            /// 节点设置  
            /// </summary>  
            public ProjectSelect ProjectSelect
            {
                get { return m_ProjectSelect; }
                set { m_ProjectSelect = value; }
            }
            /// <summary>  
            /// 显示样式  
            /// </summary>  
            public HatchStyle Style { get { return m_Style; } set { m_Style = value; Refresh(); } }
            /// <summary>  
            /// 显示颜色  
            /// </summary>  
            public Color Color { get { return m_Color; } set { m_Color = value; Refresh(); } }
            /// <summary>  
            /// 任务名称  
            /// </summary>  
            public string JobName { get { return m_JobName; } set { m_JobName = value; Refresh(); } }
            /// <summary>  
            /// 任务开始日期  
            /// </summary>  
            public DateTime StartDate { get { return m_StartDate; } set { m_StartDate = value; Refresh(); } }
            /// <summary>  
            /// 工作天数  
            /// </summary>  
            public uint WorkDay { get { return m_WorkDay; } set { m_WorkDay = value; Refresh(); } }
            /// <summary>  
            /// 资源名称  
            /// </summary>  
            public sbyte Complete { get { return m_Complete; } set { m_Complete = value; } }

            /// <summary>  
            /// 根据开始时间获取显示的区域  
            /// </summary>  
            /// <param name="p_StarDate"></param>  
            /// <param name="p_DrawSize"></param>  
            /// <param name="p_Height"></param>  
            /// <returns></returns>  
            public Rectangle GetRectangle(DateTime p_StarDate, int p_DrawSize, int p_Height)
            {
                DateTime _TimeStar = StartDate;
                GetWorkDay(ref _TimeStar);
                TimeSpan _Span = _TimeStar - p_StarDate;
                int _Day = 0;
                if (_Span.Days >= 0)
                {
                    _Day = (int)(_Span.TotalDays + 0.999999999999999);
                }
                else
                {
                    _Day = (int)_Span.TotalDays;
                }

                int _Width = _Day * p_DrawSize;
                int _WorkDay = (int)WorkDay;

                GetWorkDayCount(_TimeStar, ref _WorkDay);
                return new Rectangle(_Width, p_Height, _WorkDay * p_DrawSize, p_DrawSize);
            }

            public void GraphisDraw(Graphics p_Graphics, DateTime p_StarDate, int p_DrawSize, ref int p_Height, int p_MaxWidth, int p_MaxHeight)
            {
                if (p_Height > p_MaxHeight) return;
                Rectangle _Rectangle = GetRectangle(p_StarDate, p_DrawSize, p_Height);
                if (_Rectangle.X > p_MaxWidth) return;
                _Rectangle.Y += 5;
                _Rectangle.Height -= 5;
                HatchBrush _BlackBrush = new HatchBrush(m_Style, m_Color, Color.White);
                p_Graphics.FillRectangle(_BlackBrush, _Rectangle);
                p_Graphics.DrawRectangle(new Pen(Brushes.Black, 1), _Rectangle);
                if (m_Complete >= 0)
                {
                    StringFormat _StringFormt = new StringFormat();
                    _StringFormt.Alignment = StringAlignment.Center;
                    _StringFormt.LineAlignment = StringAlignment.Center;
                    p_Graphics.DrawString(m_Complete.ToString() + "%", new Font("宋体", 12, FontStyle.Bold), Brushes.Black, _Rectangle, _StringFormt);
                }
                p_Graphics.DrawString(m_JobName, new Font("宋体", 9), Brushes.Black, _Rectangle.X + _Rectangle.Width, _Rectangle.Y + 1);
                p_Height += p_DrawSize;
            }

            /// <summary>  
            /// 刷新  
            /// </summary>  
            private void Refresh()
            {
                if (m_ProjectSelect != null) m_ProjectSelect.Refresh();
            }

            /// <summary>  
            /// 获取工作结束日期  
            /// </summary>  
            private void GetWorkDayCount(DateTime p_StarTime, ref int p_WorkDay)
            {
                DateTime _StarTime = p_StarTime;
                for (int i = 0; i != p_WorkDay; i++)
                {
                    _StarTime = p_StarTime.AddDays(i);
                    if (_StarTime.DayOfWeek == DayOfWeek.Saturday && !m_ProjectSelect.SaturdayOfWork)
                    {
                        p_WorkDay++;
                        continue;
                    }
                    if (_StarTime.DayOfWeek == DayOfWeek.Sunday && !m_ProjectSelect.SundayOfWork)
                    {
                        p_WorkDay++;
                        continue;
                    }

                    for (int z = 0; z != m_ProjectSelect.HolidayList.Count; z++)
                    {
                        bool _Year = m_ProjectSelect.HolidayList[z].Year == _StarTime.Year;
                        bool _Month = m_ProjectSelect.HolidayList[z].Month == _StarTime.Month;
                        bool _Day = m_ProjectSelect.HolidayList[z].Day == _StarTime.Day;

                        if (_Year && _Month && _Day)
                        {
                            p_WorkDay++;
                            break;
                        }
                    }
                }
            }

            /// <summary>  
            /// 获取开始日期  
            /// </summary>  
            /// <param name="p_Value">数据</param>  
            /// <returns>日期</returns>  
            private void GetWorkDay(ref DateTime p_Value)
            {
                bool _Set = false;
                if (p_Value.DayOfWeek == DayOfWeek.Saturday && !m_ProjectSelect.SaturdayOfWork) p_Value = p_Value.AddDays(1);
                if (p_Value.DayOfWeek == DayOfWeek.Sunday && !m_ProjectSelect.SundayOfWork) p_Value = p_Value.AddDays(1);

                for (int i = 0; i != m_ProjectSelect.HolidayList.Count; i++)
                {
                    bool _Year = m_ProjectSelect.HolidayList[i].Year == p_Value.Year;
                    bool _Month = m_ProjectSelect.HolidayList[i].Month == p_Value.Month;
                    bool _Day = m_ProjectSelect.HolidayList[i].Day == p_Value.Day;

                    if (_Year && _Month && _Day)
                    {
                        p_Value = p_Value.AddDays(1);
                        _Set = true;
                        break;
                    }
                }
                if (_Set) GetWorkDay(ref p_Value);
            }


        }
    }

}

 

前端:

 

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

namespace GanttControls
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GanttControls.ProjectViewBox.ProjectNode p1 =new ProjectViewBox.ProjectNode(DateTime.Parse("2012-04-12"), 2, "新任务1");
            GanttControls.ProjectViewBox.ProjectNode p2 = new ProjectViewBox.ProjectNode(DateTime.Parse("2012-04-13"), 3, "新任务2");
            GanttControls.ProjectViewBox.ProjectNode p3 = new ProjectViewBox.ProjectNode(DateTime.Parse("2012-04-13"), 2, "新任务3");
            GanttControls.ProjectViewBox.ProjectNode p4 = new ProjectViewBox.ProjectNode(DateTime.Parse("2012-04-14"), 5, "新任务2");
            GanttControls.ProjectViewBox.ProjectNode p5 = new ProjectViewBox.ProjectNode(DateTime.Parse("2012-04-15"), 8, "新任务3");

            p1.Complete = 10;
            p2.Complete = 80;
            p3.Complete = 60;


            projectViewBox1.ProjectSelectData.HolidayList.Add(DateTime.Parse("2012-04-01"));
            projectViewBox1.ProjectSelectData.HolidayList.Add(DateTime.Parse("2012-04-12"));
            projectViewBox1.ProjectSelectData.HolidayList.Add(DateTime.Parse("2012-04-14"));
            projectViewBox1.ProjectSelectData.HolidayList.Add(DateTime.Parse("2012-04-15"));
            projectViewBox1.ProjectSelectData.HolidayList.Add(DateTime.Parse("2012-04-16"));
            projectViewBox1.ProjectSelectData.HolidayList.Add(DateTime.Parse("2012-04-17"));

            projectViewBox1.ProjectSelectData.Add(p1);
            projectViewBox1.ProjectSelectData.Add(p2);
            projectViewBox1.ProjectSelectData.Add(p3);
            projectViewBox1.ProjectSelectData.Add(p4);
            projectViewBox1.ProjectSelectData.Add(p5);

           
        }
    }
}

 

 

 

转载于:https://www.cnblogs.com/Mayvar/archive/2012/04/12/wanghonghua_201204120938.html

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页