本人想做一个甘特表格控件,主要实现如下功能:

  1、表头为相关任务列和显示日期类形式(分月、周、日、时),

  2、内容以甘特图一样显示计划和进度相关信息,根据计划开工和结束日期、计划时长 和实际开工和结束日期、实际时长画出开发甘特图内容,并以不同颜色标色,是否延误、是否提前等信息。

  3、当鼠标移动到某个任务图上时显示相关完整的任务信息,如计划开工和结束日期、计划时长,实际开工和结束日期、实际时长、当前状态,计划数量、完成数量等。

  

  目前第一步表头已实现,第二步简易实现,未获取数据库信息实现,第三步又怎么实现?本人贴出控件全部代码,希望能够得到朋友们的支持,谢谢。

一、自定义控件第一类表头,表头刻度是以每天按小时分段显示,可调整刻度数

二、自定义控件第二类表头,表头是以每天分段显示。

三、自定义控件第三类表头,表头刻度是以按周分段显示。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;using System.Threading.Tasks;
using System.Management;//滚动条
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Runtime.InteropServices;
using System.Windows.Forms.VisualStyles; /*
using System.Drawing;//提供对GDI+基本图形功能的访问
using System.Drawing.Drawing2D;//提供高级的二维和矢量图像功能
using System.Drawing.Imaging;//提供高级GDI+图像处理功能
using System.Drawing.Printing;//提供打印相关服务
using System.Drawing.Text;//提供高级GDI+排版功能
using System.Drawing.Design;//扩展设计时,用户界面逻辑和绘制的类。用于扩展,自定义Graphics类主要成员方法:
名称            说明
DrawArc         画弧
DrawBezier      画立体的贝塞尔曲线
DrawBeziers     画连续立体的贝塞尔曲线
DrawClosedCurve 画闭合曲线
DrawCurve       画曲线
DrawEllipse     画椭圆
DrawImage      画图像
DrawLine        画线
DrawPath        通过路劲画线和曲线
DrawPie         画饼图
DrawPolygon     画多边形
DrawRectangle   画矩形
DrawString      绘制文字
FillEllipse     填充椭圆
FillPath        填充路劲
FillPie         填充饼图
FillPolygon     填充多边形
FillRectangle   填充矩形
FillRectangles  填充矩形组
FillRegion      填充区域
*/
namespace MyGanttTitleControl
{public partial class GanttTitle: UserControl{public GanttTitle(){SetStyle(ControlStyles.AllPaintingInWmPaint, true);SetStyle(ControlStyles.UserPaint, true);SetStyle(ControlStyles.OptimizedDoubleBuffer,true);SetStyle(ControlStyles.Selectable,true);SetStyle(ControlStyles.ResizeRedraw, true);SetStyle(ControlStyles.SupportsTransparentBackColor, true);InitializeComponent();}//枚举周星期值public enum _meWeekValue{Monday = 1,Tuesday = 2,Wednesday = 3,Thursday = 4,Friday = 5,Saturday = 6,Sunday = 7}private _meWeekValue _firstDayofWeek = _meWeekValue.Sunday;[Category("表头设置"), Description("每周第一天是星期几")]public _meWeekValue FirstDayofWeek{get { return _firstDayofWeek; }set { _firstDayofWeek = value; }}//枚举每年第一周public enum _meFirstWeekofYear{FirstDayofYear = 1,//每年第一天起为第一周FirstDayofWeek = 2//每年当周的第一天起为第一周,以FirstDayofWeek设置为准        }private _meFirstWeekofYear _firstDayofYear = _meFirstWeekofYear.FirstDayofYear;[Category("表头设置"), Description("每年第一周")]public _meFirstWeekofYear FirstDayofYear{get { return _firstDayofYear; }set { _firstDayofYear = value; }}private DateTime  tempGanttDate;private DateTime _startGanttDate = DateTime.Now.Date;[Category("表头设置"), Description("起始日期")]public DateTime GanttStartDate{get { return _startGanttDate; }set {tempGanttDate = _startGanttDate;_startGanttDate = value.Date;if (DateTime.Compare(_startGanttDate , _endGanttDate)>0) _startGanttDate = tempGanttDate;}}private DateTime _endGanttDate = DateTime.Now.Date.AddDays(43);[Category("表头设置"), Description("结束日期")]public DateTime GanttEndDate{get { return _endGanttDate; }set {tempGanttDate = _endGanttDate;_endGanttDate = value.Date ;if (DateTime.Compare(_startGanttDate, _endGanttDate) > 0) _endGanttDate = tempGanttDate;}}//甘特图表每格表头方式public enum _ganttTitleCellWay{OnTime = 1,//按24时计ByTheDay = 2,//按天计Weekly = 3,//按周计UserDefinedDays = 4//自定义天数
      }private _ganttTitleCellWay _setGanttTitleCellWay = _ganttTitleCellWay.OnTime;[Category("表头设置"),Description("甘特图表每格表头方式")]public _ganttTitleCellWay SetGanttTitleCellWay{get { return _setGanttTitleCellWay; }set { _setGanttTitleCellWay = value;switch (_setGanttTitleCellWay.ToString()){case "OnTime": _maxCellScale = 6;break;case "ByTheDay": _maxCellScale = 1;break;case "Weekly": _maxCellScale = 7;break;case "UserDefinedDays": _maxCellScale = 1;break;}}}private int _maxCellScale = 6;[Category("表头设置"), Description("表头单元格最大刻度")]public int MaxCellScale{get { return _maxCellScale; }set{int  _maxDays=DateTime.IsLeapYear(GanttStartDate.Year)==true?366:355;_maxCellScale = value;switch (SetGanttTitleCellWay.ToString()){case "OnTime": {if (_maxCellScale <= 0 || _maxCellScale > 24) { _maxCellScale = 6; } else { _maxCellScale = value; }break;}case "ByTheDay":{if (_maxCellScale != 1) { _maxCellScale = 1; } else { _maxCellScale = value; }break;}case "Weekly":{if (_maxCellScale != 7) { _maxCellScale = 7; } else { _maxCellScale = value; }break;}case "UserDefinedDays":{if (_maxCellScale <= 0 || _maxCellScale > _maxDays) { _maxCellScale = 1; } else { _maxCellScale = value; }break;}}}}private int _titleCellWidth = 140;[Category("表头设置"), Description("表头单元格宽度")]public int TitleCellWidth{get { return _titleCellWidth; }set {  _titleCellWidth = value; }}private int _titleCellHeight = 45;[Category("表头设置"), Description("表头单元格宽度")]public int TitleCellHeight{get { return _titleCellHeight; }set { _titleCellHeight = value; }}private Color _titleBackColor=Control.DefaultForeColor ;[Category("表头设置"), Description("表头背景颜色")]public Color TitleBackColor{get { return _titleBackColor; }set { _titleBackColor = value; }}private Color _titleBorderColor = Color.SlateGray;[Category("表头设置"), Description("表头边框线颜色")]public Color TitleBorderColor{get { return _titleBorderColor; }set { _titleBorderColor = value; }}private Color _bigScaleColor = Color.Red ;[Category("表头设置"), Description("大刻度颜色")]public Color BigScaleColor{get { return _bigScaleColor; }set { _bigScaleColor = value; }}private Color _smallScaleColor = Color.Black;[Category("表头设置"), Description("小刻度颜色")]public Color SmallScaleColor{get { return _smallScaleColor; }set { _smallScaleColor = value; }}private Color _bigScaleFontColor = Color.Black;[Category("表头设置"), Description("刻度文字颜色")]public Color BigScaleFontColor{get { return _bigScaleFontColor; }set { _bigScaleFontColor = value; }}private Font _titleFont = new Font("宋体", 8);[Category("表头设置"), Description("表头文字字体")]public Font TitleFont{get { return _titleFont; }set { _titleFont = value; }}private int _backBigWidth = 800;[Category("表头设置"), Description("最大宽度")]public int BackBigWidth{get { return _backBigWidth; }set { _backBigWidth = value; }}private int _backBigHeight = 600;[Category("表头设置"), Description("最大高度")]public int BackBigHeight{get { return _backBigHeight; }set { _backBigHeight = value; }}private int _contCellHeight = 25;[Category("表内容设置"), Description("内容单元格宽度")]public int ContCellHeight{get { return _contCellHeight; }set { _contCellHeight = value; }}private int _contCellRow = 6;[Category("表内容设置"), Description("表格行数")]public int ContCellRow{get { return _contCellRow; }set { _contCellRow = value; }}private int _contCellColumn = 1;[Category("表内容设置"), Description("非进度表格列数")]public int ContCellColumn{get { return _contCellColumn; }set { _contCellColumn = value; }}private Color _contBackColor = Control.DefaultBackColor ;[Category("表内容设置"), Description("表格内容背景色")]public Color ContBackColor{get { return _contBackColor; }set { _contBackColor = value; }}private Color _contFontColor = Color.Black;[Category("表内容设置"), Description("表格内容文字颜色")]public Color ContFontColor{get { return _contFontColor; }set { _contFontColor = value; }}private Color _contGanttBorderColor = Color.DarkGray;[Category("表内容设置"), Description("进度框边框颜色")]public Color ContGanttBorderColor{get { return _contGanttBorderColor; }set { _contGanttBorderColor = value; }}private Color _contGanttFillColor = Color.Blue;[Category("表内容设置"), Description("进度框填充颜色")]public Color ContGanttFillColor{get { return _contGanttFillColor; }set { _contGanttFillColor = value; }}//获取到下一周第一天的天数private int GetFirstDay(int setWeekNum,int curWeekNum){curWeekNum = curWeekNum == 0 ? 7 : curWeekNum;if (curWeekNum <= setWeekNum){ return setWeekNum - curWeekNum; }else{ return 7 - curWeekNum + setWeekNum; }}private DateTime GetFirstDay(DateTime lblCurDate,int setWeekNum,int curWeekNum){int curNum;curWeekNum = curWeekNum == 0 ? 7 : curWeekNum;if (curWeekNum < setWeekNum){ curNum= setWeekNum - curWeekNum; }else{  curNum= 7 - curWeekNum + setWeekNum; }return lblCurDate.AddDays(curNum-7);}//获取参数日期在当前年份的当前周数private int GetCurWeek(DateTime lblCurDate){int curWeekNum = 0;int curDays=lblCurDate.DayOfYear;int secWeekFirstDay = GetFirstDay((int)FirstDayofWeek, (int)DateTime.Parse(lblCurDate.Year.ToString() + "-1-1").DayOfWeek);if (FirstDayofYear.ToString() == "FirstDayofYear"){if (secWeekFirstDay != 0) { curDays = curDays - secWeekFirstDay; }curWeekNum = curDays % 7 > 0 ? curDays / 7 + 1 : curDays / 7;if (secWeekFirstDay != 0) { curWeekNum++; }}else{curDays = curDays - secWeekFirstDay;curWeekNum = curDays % 7 > 0 ? curDays / 7 + 1 : curDays / 7;}return curWeekNum;}private int curWeek;private DateTime tempDay;private Pen pn,p;private Brush b;private StringFormat titleFormat;/// <summary>/// 按时绘制图表/// </summary>/// <param name="e"></param>/// <param name="totalDays"></param>private void OnTime_Paint(PaintEventArgs e, int totalDays){int i, n;for (i = 1; i <= totalDays; i++){e.Graphics.DrawRectangle(pn, i * TitleCellWidth, 0, TitleCellWidth, TitleCellHeight);e.Graphics.DrawLine(pn, i * TitleCellWidth, (int)TitleCellHeight / 3, (i + 1) * TitleCellWidth, (int)TitleCellHeight / 3);e.Graphics.DrawLine(pn, i * TitleCellWidth, (int)TitleCellHeight / 3 * 2, (i + 1) * TitleCellWidth, (int)TitleCellHeight / 3 * 2);tempDay = GanttStartDate.AddDays(i - 1);curWeek = GetCurWeek(tempDay);//画年月日及周数e.Graphics.DrawString(tempDay.ToShortDateString(), TitleFont, b, (i * TitleCellWidth + (i + 1) * TitleCellWidth) / 2, 8, titleFormat);e.Graphics.DrawString("第" + curWeek.ToString() + "周  " + tempDay.DayOfWeek.ToString(), TitleFont, b, (i * TitleCellWidth + (i + 1) * TitleCellWidth) / 2, (int)TitleCellHeight / 3 + 10, titleFormat);//画刻度线for (n = 0; n < MaxCellScale; n++){if (n > 0){p = new Pen(SmallScaleColor, 1);e.Graphics.DrawLine(p, i * TitleCellWidth + (int)TitleCellWidth / MaxCellScale * n, TitleCellHeight, i * TitleCellWidth + (int)TitleCellWidth / MaxCellScale * n, TitleCellHeight - 3);e.Graphics.DrawString((24 / MaxCellScale * n).ToString(), TitleFont, b, i * TitleCellWidth + (int)TitleCellWidth / MaxCellScale * n, TitleCellHeight / 3 * 2 + 8, titleFormat);}else{p = new Pen(BigScaleColor, 1);e.Graphics.DrawLine(p, i * TitleCellWidth + (int)TitleCellWidth / MaxCellScale * n, TitleCellHeight, i * TitleCellWidth + (int)TitleCellWidth / MaxCellScale * n, TitleCellHeight - 5);}}}//画最后一行线框p = new Pen(BigScaleColor, 1);e.Graphics.DrawLine(p, (totalDays + 1) * TitleCellWidth, TitleCellHeight, (totalDays + 1) * TitleCellWidth, TitleCellHeight - 5);}/// <summary>/// 按天绘制图表/// </summary>/// <param name="e"></param>/// <param name="totalDays"></param>/// <param name="resWeek"></param>/// <param name="maxWeek"></param>/// <param name="maxCurWeek"></param>private void ByTheDay_Paint(PaintEventArgs e,int totalDays,int resWeek, int maxWeek, int maxCurWeek){int i;int tempWeek, tempNum=0;int oldWeek = resWeek - 1;for (i = 1; i <= totalDays; i++){tempDay = GanttStartDate.AddDays(i - 1);curWeek = GetCurWeek(tempDay);if (DateTime.Compare(tempDay, DateTime.Parse(GanttStartDate.Year.ToString() + "-12-31")) > 0){ tempWeek = maxWeek - resWeek + 1; }else{ tempWeek = curWeek - resWeek + 1; }if (oldWeek != curWeek){e.Graphics.DrawRectangle(pn, tempWeek * TitleCellWidth, 0, TitleCellWidth, TitleCellHeight);e.Graphics.DrawLine(pn, tempWeek * TitleCellWidth, (int)TitleCellHeight / 3, (tempWeek + 1) * TitleCellWidth, (int)TitleCellHeight / 3);e.Graphics.DrawLine(pn, tempWeek * TitleCellWidth, (int)TitleCellHeight / 3 * 2, (tempWeek + 1) * TitleCellWidth, (int)TitleCellHeight / 3 * 2);e.Graphics.DrawString(tempDay.Year.ToString() + "年" + tempDay.Month.ToString() + "月  " + "第" + curWeek.ToString() + "周", TitleFont, b, (tempWeek * TitleCellWidth + (tempWeek + 1) * TitleCellWidth) / 2, 10, titleFormat);oldWeek = curWeek;}if (i == 1){DateTime tempFirstDate = GetFirstDay(GanttStartDate, (int)FirstDayofWeek, (int)GanttStartDate.DayOfWeek);tempNum = tempWeek * TitleCellWidth + TitleCellWidth / 7 * (GanttStartDate - tempFirstDate).Days;}else{tempNum = tempNum + TitleCellWidth / 7;}e.Graphics.DrawLine(pn, tempNum, (int)TitleCellHeight / 3, tempNum, (int)TitleCellHeight);e.Graphics.DrawString(tempDay.Day.ToString(), TitleFont, b, (tempNum * 2 + (int)(TitleCellWidth / 7)) / 2, (int)TitleCellHeight / 3 * 2 + 10, titleFormat);switch ((int)tempDay.DayOfWeek){case 0: e.Graphics.DrawString("日", TitleFont, b, (tempNum * 2 + TitleCellWidth / 7) / 2, TitleCellHeight / 3 + 10, titleFormat);break;case 1: e.Graphics.DrawString("一", TitleFont, b, (tempNum * 2 + TitleCellWidth / 7) / 2, TitleCellHeight / 3 + 10, titleFormat);break;case 2: e.Graphics.DrawString("二", TitleFont, b, (tempNum * 2 + TitleCellWidth / 7) / 2, TitleCellHeight / 3 + 10, titleFormat);break;case 3: e.Graphics.DrawString("三", TitleFont, b, (tempNum * 2 + TitleCellWidth / 7) / 2, TitleCellHeight / 3 + 10, titleFormat);break;case 4: e.Graphics.DrawString("四", TitleFont, b, (tempNum * 2 + TitleCellWidth / 7) / 2, TitleCellHeight / 3 + 10, titleFormat);break;case 5: e.Graphics.DrawString("五", TitleFont, b, (tempNum * 2 + TitleCellWidth / 7) / 2, TitleCellHeight / 3 + 10, titleFormat);break;case 6: e.Graphics.DrawString("六", TitleFont, b, (tempNum * 2 + TitleCellWidth / 7) / 2, TitleCellHeight / 3 + 10, titleFormat);break;}}//画最后一行线框e.Graphics.DrawLine(pn, tempNum + (int)(TitleCellWidth / 7), (int)TitleCellHeight / 3, tempNum + (int)(TitleCellWidth / 7), (int)TitleCellHeight);}/// <summary>/// 按周绘制图表/// </summary>/// <param name="e"></param>/// <param name="totalDays"></param>/// <param name="resMonth"></param>/// <param name="maxCurMonth"></param>/// <param name="maxMonth"></param>private void Weekly_Paint(PaintEventArgs e,int totalDays,int resMonth,int  maxCurMonth,int  maxMonth){int i,n;int resWeek = 0,maxWeek = 0, maxCurWeek = 0, oldWeek = resWeek - 1;e.Graphics.DrawLine(pn, TitleCellWidth, (int)TitleCellHeight / 3, (maxMonth - resMonth + 2) * TitleCellWidth, (int)TitleCellHeight / 3);e.Graphics.DrawLine(pn, TitleCellWidth, (int)TitleCellHeight / 3 * 2, (maxMonth - resMonth + 2) * TitleCellWidth, (int)TitleCellHeight / 3 * 2);for (i = 1; i <= maxMonth-resMonth+1; i++){e.Graphics.DrawRectangle(pn, i * TitleCellWidth, 0, TitleCellWidth, TitleCellHeight / 3 * 2);e.Graphics.DrawLine(pn, i * TitleCellWidth, (int)TitleCellHeight / 3, (i + 1) * TitleCellWidth, TitleCellHeight / 3);if (maxMonth <= 12){e.Graphics.DrawString(GanttStartDate.Year.ToString() + "年" + (resMonth+i-1).ToString() + "月", TitleFont, b, (i * TitleCellWidth + (i + 1) * TitleCellWidth) / 2, TitleCellHeight / 6+3, titleFormat);}else{e.Graphics.DrawString((GanttStartDate.Year + 1).ToString() + "年" + (i - 12).ToString() + "月", TitleFont, b, (i * TitleCellWidth + (i + 1) * TitleCellWidth) / 2, TitleCellHeight / 6+3, titleFormat);}}//初始周数resWeek = GetCurWeek(GanttStartDate);//当年最大周数maxCurWeek = GetCurWeek(DateTime.Parse(GanttStartDate.Year.ToString() + "-12-31"));//最后日期所在周数maxWeek = GetCurWeek(GanttStartDate.AddDays(totalDays));if (DateTime.Compare(GanttStartDate.AddDays(totalDays), DateTime.Parse(GanttStartDate.Year.ToString() + "-12-31")) > 0){ maxWeek = maxCurWeek - resWeek + maxCurWeek - 1; }//开始日期当月最大和最小周数int curFirstWeek = GetCurWeek(DateTime.Parse(GanttStartDate.Year.ToString() + "-" + GanttStartDate.Month.ToString() + "-1"));curWeek = GetCurWeek(DateTime.Parse(GanttStartDate.Year.ToString() + "-" + GanttStartDate.Month.ToString() + "-" + DateTime.DaysInMonth(GanttStartDate.Year, GanttStartDate.Month).ToString()));int startPos;if (resWeek == curFirstWeek){ startPos = TitleCellWidth + TitleCellWidth / 4; }else{ startPos = TitleCellWidth + TitleCellWidth / 4 * (resWeek - curFirstWeek); }//画起始周数线e.Graphics.DrawLine(pn, startPos - TitleCellWidth / 4, TitleCellHeight / 3, startPos - TitleCellWidth / 4, TitleCellHeight / 3 * 2);e.Graphics.DrawLine(p, startPos - TitleCellWidth / 4, TitleCellHeight, startPos - TitleCellWidth / 4, TitleCellHeight - 3);//画起始周数DateTime tempFirstDate = GetFirstDay(GanttStartDate, (int)FirstDayofWeek, (int)GanttStartDate.DayOfWeek);e.Graphics.DrawString(tempFirstDate.Day.ToString(), TitleFont, b, startPos - TitleCellWidth / 4, (TitleCellHeight + TitleCellHeight / 3 * 2) / 2, titleFormat);for (n = 0; n <= maxWeek - resWeek; n++){//画周数线e.Graphics.DrawLine(pn, n * TitleCellWidth / 4 + startPos, TitleCellHeight / 3, n * TitleCellWidth / 4 + startPos, TitleCellHeight / 3 * 2);e.Graphics.DrawString((resWeek + n).ToString()+"周", TitleFont, b, n * TitleCellWidth / 4 + startPos - 18, (TitleCellHeight / 3 * 2 + TitleCellHeight / 3) / 2 + 2, titleFormat);//画日期刻度e.Graphics.DrawLine(p, n * TitleCellWidth / 4 + startPos, TitleCellHeight, n * TitleCellWidth / 4 + startPos, TitleCellHeight - 3);e.Graphics.DrawString(tempFirstDate.AddDays((n + 1) * 7).Day.ToString(), TitleFont, b, n * TitleCellWidth / 4 + startPos, (TitleCellHeight + TitleCellHeight / 3 * 2) / 2, titleFormat);}e.Graphics.DrawLine(pn, TitleCellWidth * (maxMonth - resMonth + 2), TitleCellHeight / 3 * 2, TitleCellWidth * (maxMonth - resMonth + 2), TitleCellHeight);}protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);int tempWidth = 0;int resWeek=0, maxWeek=0, maxCurWeek=0;int resMonth=0, maxCurMonth=12, maxMonth=0;int newWidth = this.Size.Width;int newHeight = this.Size.Height;int tempHeight = TitleCellHeight + ContCellHeight * (ContCellRow - 1);int totalDays = (GanttEndDate - GanttStartDate).Days + 1;int lastNum=1;switch (SetGanttTitleCellWay.ToString()){case "OnTime":{tempWidth = (totalDays + 1) * TitleCellWidth;lastNum = totalDays;break;}case "ByTheDay":{//初始周数resWeek = GetCurWeek(GanttStartDate);//当年最大周数maxCurWeek = GetCurWeek(DateTime.Parse(GanttStartDate.Year.ToString() + "-12-31"));//最后日期所在周数maxWeek = GetCurWeek(GanttStartDate.AddDays(totalDays));if (DateTime.Compare(GanttStartDate.AddDays(totalDays), DateTime.Parse(GanttStartDate.Year.ToString() + "-12-31")) > 0) {maxWeek = maxCurWeek - resWeek + maxCurWeek + 1; }tempWidth = (maxWeek - resWeek + 2) * TitleCellWidth;lastNum = (maxWeek - resWeek + 1);break;}case "Weekly":{//初始月份resMonth = GanttStartDate.Month;//最后日期所在月份maxMonth = GanttStartDate.AddDays(totalDays).Month;if (DateTime.Compare(GanttStartDate.AddDays(totalDays), DateTime.Parse(GanttStartDate.Year.ToString() + "-12-31")) > 0) { maxMonth =maxCurMonth-resMonth+ maxCurMonth-1;}tempWidth = (maxMonth - resMonth + 2) * TitleCellWidth;lastNum = maxMonth - resMonth + 1;break;}case "UserDefinedDays":{break;}}//拖动滚动条if (tempWidth > this.Size.Width) { newWidth = tempWidth; }if (tempHeight > this.Size.Height) { newHeight = tempHeight; }int bgWidht = newWidth;int bgHeight = newHeight;if (bgWidht > BackBigWidth) bgWidht = BackBigWidth;if (bgHeight > BackBigHeight) bgHeight = BackBigHeight;//this.Size = new System.Drawing.Size(bgWidht, bgHeight);this.AutoScrollMinSize = new System.Drawing.Size(newWidth + 10, newHeight + 10);e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;e.Graphics.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);pn = new Pen(TitleBorderColor, 1);//定义文字格式Brush bh =new SolidBrush(ContBackColor);b = new SolidBrush(BigScaleFontColor);p = new Pen(BigScaleColor, 1);titleFormat = new StringFormat();titleFormat.LineAlignment = StringAlignment.Center;titleFormat.Alignment = StringAlignment.Center;//画首行首列e.Graphics.FillRectangle(bh, 0, 0, newWidth, newHeight);e.Graphics.DrawRectangle(pn, 0, 0, newWidth, newHeight);e.Graphics.DrawRectangle(pn, 0, 0, TitleCellWidth, TitleCellHeight);e.Graphics.DrawString("生产单号", TitleFont, b, TitleCellWidth / 2, TitleCellHeight / 2, titleFormat);switch (SetGanttTitleCellWay.ToString()){case "OnTime":{OnTime_Paint(e,totalDays);break;}case "ByTheDay":{ByTheDay_Paint(e,totalDays,resWeek, maxWeek, maxCurWeek);break;}case "Weekly":{Weekly_Paint(e,totalDays,resMonth, maxCurMonth, maxMonth);break;}case "UserDefinedDays":{break;}}b = new SolidBrush(ContFontColor);p = new Pen(ContGanttBorderColor,1);Brush bg = new SolidBrush(ContGanttFillColor);for (int j = 2; j <= ContCellRow; j++){//画内容框e.Graphics.DrawRectangle(pn, 0, TitleCellHeight + (j - 2) * ContCellHeight, TitleCellWidth, ContCellHeight);//画任务内容e.Graphics.DrawString("F160256-00" + (j - 1).ToString() + "-00", TitleFont, b, TitleCellWidth / 2, TitleCellHeight + (j - 2) * ContCellHeight + ContCellHeight/2, titleFormat);//画进度框e.Graphics.DrawRectangle(pn, TitleCellWidth, TitleCellHeight + (j - 2) * ContCellHeight, TitleCellWidth * lastNum, ContCellHeight);e.Graphics.DrawRectangle(p, TitleCellWidth + 2, TitleCellHeight + (j - 2) * ContCellHeight + 2, TitleCellWidth * (j - 1), ContCellHeight - 4);e.Graphics.FillRectangle(bg, TitleCellWidth + 2, TitleCellHeight + (j - 2) * ContCellHeight + 2, TitleCellWidth * (j - 1), ContCellHeight - 4);}}}//数据节点;public class GanttNodes{private string _gnlJobCode;    //生产单号private string _gnlProcNo;     //工序号private string _gnlProcName;   //工序名称private string _gnlMachine;    //计划机床代号+机床名称private string _gnlOpreator;   //计划操作员private DateTime _gnlStartDate; //开始日期时间private DateTime _gnlEndDate; //结束日期时间private float _gnlDuration;    //时长private enum _gnlUnitMode{Second = 0, //秒Minute = 1, //分钟Hour = 2,   //小时Day = 3,    //天Week = 4,   //周
        }private _gnlUnitMode gntc_UnitMode = _gnlUnitMode.Minute;private float _gnlDaysofTime;  //当天的有效时长;public string gntc_JobCode{get { return _gnlJobCode; }set { _gnlJobCode = value; }}public string gntc_ProcNo{get { return _gnlProcNo; }set { _gnlProcNo = value; }}public string gntc_ProcName{get { return _gnlProcName; }set { _gnlProcName = value; }}public string gntc_Machine{get { return _gnlMachine; }set { _gnlMachine = value; }}public string gntc_Opreator{get { return _gnlOpreator; }set { _gnlOpreator = value; }}public DateTime gntc_StartDate{get { return _gnlStartDate; }set { _gnlStartDate = value; }}public DateTime gntc_EndDate{get { return _gnlEndDate; }set { _gnlEndDate = value; }}public float gntc_Duration{get { return _gnlDuration; }set { _gnlDuration = value; }}private _gnlUnitMode gntc_UseUnitMode{set { gntc_UnitMode = value; }get { return gntc_UnitMode; }}public float gntc_DaysofTime{get { return _gnlDaysofTime; }set { _gnlDaysofTime = value; }}/// <summary>/// 时长单位转换/// </summary>/// <param name="_gnlLong">时长</param>/// <param name="_gnlResUnit">原时长单位</param>/// <param name="_gnlNewUnit">新时长单位</param>/// <returns></returns>private float DurationTrans(float _gnlLong,  _gnlUnitMode _gnlResUnit,_gnlUnitMode _gnlNewUnit,float _gnlDOT){float result=0;switch (_gnlResUnit.ToString()){case "Second":{switch (_gnlNewUnit.ToString()){case "Second": result = (float)_gnlLong;break;case "Minute": result = (float)_gnlLong / 60;break;case "Hour": result = (float)_gnlLong / (60 * 60);break;case "Day": result = (float)(_gnlLong / (60 * 60 * _gnlDOT));break;case "Week": result = (float)(_gnlLong / (60 * 60 * _gnlDOT * 7));break;}}break;case "Minute":{switch (_gnlNewUnit.ToString()){case "Second": result = (float)_gnlLong * 60;break;case "Minute": result = (float)_gnlLong;break;case "Hour": result = (float)_gnlLong / 60;break;case "Day": result = (float)(_gnlLong / (60 * _gnlDOT));break;case "Week": result = (float)_gnlLong / (60 * _gnlDOT*7);break;}}break;case "Hour":{switch (_gnlNewUnit.ToString()){case "Second": result = (float)_gnlLong * 60*60;break;case "Minute": result = (float)_gnlLong * 60;break;case "Hour": result = (float)_gnlLong;break;case "Day": result = (float)_gnlLong / _gnlDOT;break;case "Week": result = (float)_gnlLong / (_gnlDOT * 7);break;}}break;case "Day":{switch (_gnlNewUnit.ToString()){case "Second": result = (float)_gnlLong * _gnlDOT*60*60;break;case "Minute": result = (float)_gnlLong * _gnlDOT*60;break;case "Hour": result = (float)_gnlLong* _gnlDOT;break;case "Day": result = (float)_gnlLong;break;case "Week": result = (float)_gnlLong /7;break;}}break;case "Week":{switch (_gnlNewUnit.ToString()){case "Second":result = (float)_gnlLong*7*_gnlDOT*60*60;break;case "Minute": result = (float)_gnlLong * 7 * _gnlDOT * 60;break;case "Hour":result = (float)_gnlLong*7*_gnlDOT;break;case "Day":result = (float)_gnlLong*7;break;case "Week": result = (float)_gnlLong;break;}}break;}return result;}public GanttNodes(){}}
}

转载于:https://www.cnblogs.com/172838427/p/4635264.html

c# 自定义甘特表格控件 (原创 学习中请指导)相关推荐

  1. SilverLight学习笔记--如何在xaml文件中操作用户在后台代码定义的类(2)--示例篇:创建一个登录控件(原创)(转载本文请注明出处)...

    本文将示例如何运用前篇所写知识来建立一个用户自定义的登录控件.此控件界面非常简单,主要涉及的知识点是:   如何创建用户控件(包括对此控件的自定义事件和属性的编写,此处我们将创建一个名为LoginBo ...

  2. Angular19 自定义表单控件

    1 需求 当开发者需要一个特定的表单控件时就需要自己开发一个和默认提供的表单控件用法相似的控件来作为表单控件:自定义的表单控件必须考虑模型和视图之间的数据怎么进行交互 2 官方文档 -> 点击前 ...

  3. Angular: [ControlValueAccessor] 自定义表单控件

    Angular: [ControlValueAccessor] 自定义表单控件 我们在实际开发中,通常会遇到各种各样的定制化功能,会遇到有些组件会与 Angular 的表单进行交互,这时候我们一般会从 ...

  4. android自定义table,Android 自定义表格控件

    Android 自定义表格控件 发布时间:2018-08-20 17:07, 浏览次数:487 , 标签: Android 1.简介 tabview是一款开源表格控件,可以通过xml属性设置行列数.设 ...

  5. 甘特图控件如何自定义绘图?DevExpress Winforms帮你忙

    DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...

  6. ESP32 开发笔记(四)LVGL控件学习 Table 表格控件

    先看效果,创建一个简单的表格 开发板购买链接https://item.taobao.com/item.htm?spm=a2oq0.12575281.0.0.50111deb2Ij1As&ft= ...

  7. ExtJS4.2学习(10)分组表格控件--GroupingGrid

    分组表格控件在我们的开发中经常被用到,GroupingGrid分组表格就是在普通表格的基础上,根据某一列的数据显示表格中的数据分组的表格控件.举个例子给大家,比如某些信息用树形显示觉得有点大才小用,树 ...

  8. ExtJS4.2学习(10)分组表格控件--GroupingGrid(转)

    鸣谢网址:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-17/179.html ------------- ...

  9. Angular学习笔记(五) - 自定义表单控件

    本文简单介绍封装使用ngModel实现自定义表单控件的过程. NgModel 相关 NgModel NgModel用于从作用域创建一个FormControl实例,并将它绑定到一个表单控件元素. ngM ...

最新文章

  1. 美多商城之购物车(购物车存储方案)
  2. 如何导出android studio程序,Android Studio 如何导出 Jar 给 Unity 使用
  3. WinForm 曲线图控件
  4. Windows API获取系统配置文件的配置参数
  5. Hbase 预写日志WAL处理源码分析之 LogCleaner
  6. Android Studio常用插件
  7. java web随机抽取_java实现随机抽取奖品工具类
  8. Deepin Linux 15.10 发布
  9. 搜狗入选Fast Company最具创新力公司,智能翻译机表现抢眼
  10. centos mysql-5.5.20_mysql-5.5.20+CentOS 6.2 编译安装全过程详解(2)
  11. Koding VM 配置nginx 小记
  12. 5、lvs使用进阶(01)
  13. Windows Server 2016关闭自动更新
  14. 关于使用js的setAttribute和getAttribute取dom属性在ie ff safri下的问题
  15. 华为(BGP路由技术)
  16. hr常见面试题及答案
  17. 【Java】命名规范
  18. Echarts实现中国地图线路图特效(一对多发射点)
  19. linux下easyconnect启动不能连接外网
  20. MIPI解决方案 ICN6202:MIPI DSI转LVDS转换芯片

热门文章

  1. 多地使用无人机执法引争议
  2. 怎么在CAD编辑软件中批量打印图纸
  3. 【兴趣】收集一些不玩后悔系列的单机游戏
  4. c++ vs2012 使用 zint 生成条形码
  5. C#悬浮窗口 图像背景
  6. 桥接路由器总是掉线_Win7系统下tl-wr886n无线桥接上网总掉线如何解决
  7. 【仅我有】2018-10《信息资源管理 02378》真卷,有答案版本
  8. 基于51单片机的篮球记分牌
  9. Camera Provider注册、初始化、调用时序图_独家原创
  10. 用Matlab生成扫频Cosine信号