private void InitControl() { this.ganttControl1.ShowTooltip = true; this.ganttControl1.StartTime = DateTime.Now.AddHours(-3); this.ganttControl1.TotalScale = 24 * 4; Random ran = new Random(); for (int i = 0; i < 10; i++) { var taskCenter = this.ganttControl1.AddTaskCenter(i.ToString(), "测试机台" + i); for (int j = 0; j < 10; j++) { var hour = ran.Next(1, 10); var task = new Task((i * 100 + j).ToString(), "测试任务" + (i * 100 + j).ToString(), DateTime.Now.AddHours(-1), new TimeSpan(hour, 0, 0)); if (i == 0) { task.IsCustomerLock = true; } taskCenter.AddTask(task); } } }
public abstract void DrawTask(Graphics graphics, Rectangle taskRect, Task task, bool isSelected, bool drawPercent);
public override void DrawTask(Graphics g, Rectangle rect, Task task, bool isSelected, bool drawPercent) { Color start = InterpolateColors(task.BackColor, Color.White, 0.4f); Color end = InterpolateColors(task.BackColor, Color.FromArgb(191, 210, 234), 0.7f); using (Pen m_Pen = new Pen(task.BorderColor, 1)) g.DrawRectangle(m_Pen, rect); if (isSelected) { using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, this.SelectionTaskColor, LinearGradientMode.Vertical)) { g.FillRectangle(aGB, rect); } } else { using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical)) g.FillRectangle(aGB, rect); } g.TextRenderingHint = TextRenderingHint.SystemDefault; if (drawPercent) { using (Pen percent_Pen = new Pen(Color.DarkGreen, 2.0f)) { g.DrawLine(percent_Pen, rect.X, rect.Top + (rect.Bottom - rect.Top) / 2, rect.Left + (int)((rect.Right - rect.Left) * task.Percent), rect.Top + (rect.Bottom - rect.Top) / 2); } } g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; using (StringFormat sf = new StringFormat()) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; g.DrawString(task.Name, this.Font, SystemBrushes.WindowText, rect, sf); } }