private void SaveImage(Control control) { GanttChart gantt = control as GanttChart; string filePath = Interaction.InputBox("Where to save the file?", "Save image", "C:\\Temp\\GanttChartTester.jpg"); if (filePath.Length == 0) { return; } gantt.SaveImage(filePath); Interaction.MsgBox("Picture saved", MsgBoxStyle.Information); }
private void SaveImageToolStripMenuItem_Click(Object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; Control chart = null; if (menuItem != null) { ContextMenuStrip calendarMenu = menuItem.Owner as ContextMenuStrip; if (calendarMenu != null) { chart = calendarMenu.SourceControl; } } SaveImage(chart); }
public static GanttChart.GanttChart returnGantt(Project project) { /* * This method takes a project and returns a Gantt Chart object that can be displayed and manipulated */ GanttChart.GanttChart ganttChart1 = new GanttChart.GanttChart(); try { //Gantt chart settings ganttChart1.AllowChange = false; ganttChart1.FromDate = project.dateStarted.AddDays(-2); ganttChart1.ToDate = ModelView.taskLastFinishing(project).AddDays(2); ganttChart1.GridColor = Pens.Black; ganttChart1.ForeColor = Color.Black; ganttChart1.BackColor = UI.chartColour; int barIndex = 0; //For each task add a relevant row in the gantt chart foreach (Task task in project.taskList) { string taskName = task.TaskName; DateTime fromTime = task.StartDate; DateTime toTime = task.EstimatedFinishingDate; Color barColor = UI.dataPointColour; Color barHoverColor = UI.dataPointHoverColour; barIndex++; BarInformation bInf = new BarInformation(taskName, fromTime, toTime, barColor, barHoverColor, barIndex); ganttChart1.AddChartBar(taskName, bInf, fromTime, toTime, barColor, barHoverColor, barIndex); } return(ganttChart1); } catch (Exception) { return(null); } }
private void Form1_Load(object sender, EventArgs e) { SaveImageToolStripMenuItem.Click += new EventHandler(SaveImageToolStripMenuItem_Click); txtLog = new TextBox(); txtLog.Dock = DockStyle.Fill; txtLog.Multiline = true; txtLog.Enabled = false; txtLog.ScrollBars = ScrollBars.Horizontal; tableLayoutPanel1.Controls.Add(txtLog, 0, 3); //first Gantt Chart ganttChart1 = new GanttChart(); ganttChart1.AllowChange = false; ganttChart1.Dock = DockStyle.Fill; ganttChart1.FromDate = new DateTime(2015, 12, 12, 0, 0, 0); ganttChart1.ToDate = new DateTime(2015, 12, 24, 0, 0, 0); tableLayoutPanel1.Controls.Add(ganttChart1, 0, 1); ganttChart1.MouseMove += new MouseEventHandler(ganttChart1.GanttChart_MouseMove); ganttChart1.MouseMove += new MouseEventHandler(GanttChart1_MouseMove); ganttChart1.MouseDragged += new MouseEventHandler(ganttChart1.GanttChart_MouseDragged); ganttChart1.MouseLeave += new EventHandler(ganttChart1.GanttChart_MouseLeave); ganttChart1.ContextMenuStrip = ContextMenuGanttChart1; List <BarInformation> lst1 = new List <BarInformation>(); lst1.Add(new BarInformation("Row 1", new DateTime(2015, 12, 12), new DateTime(2015, 12, 16), Color.Aqua, Color.Khaki, 0)); lst1.Add(new BarInformation("Row 2", new DateTime(2015, 12, 13), new DateTime(2015, 12, 20), Color.AliceBlue, Color.Khaki, 1)); lst1.Add(new BarInformation("Row 3", new DateTime(2015, 12, 14), new DateTime(2015, 12, 24), Color.Violet, Color.Khaki, 2)); lst1.Add(new BarInformation("Row 2", new DateTime(2015, 12, 21), new DateTime(2015, 12, 22, 12, 0, 0), Color.Yellow, Color.Khaki, 1)); lst1.Add(new BarInformation("Row 1", new DateTime(2015, 12, 17), new DateTime(2015, 12, 24), Color.LawnGreen, Color.Khaki, 0)); foreach (BarInformation bar in lst1) { ganttChart1.AddChartBar(bar.RowText, bar, bar.FromTime, bar.ToTime, bar.Color, bar.HoverColor, bar.Index); } }
private void FrmChart_Load(object sender, EventArgs e) { SaveImageToolStripMenuItem.Click += new EventHandler(SaveImageToolStripMenuItem_Click); txtLog = new TextBox(); txtLog.Dock = DockStyle.Fill; txtLog.Multiline = true; txtLog.Enabled = false; txtLog.ScrollBars = ScrollBars.Horizontal; //tableLayoutPanel1.Controls.Add(txtLog, 0, 1); //first Gantt Chart chart = new GanttChart(); chart.AllowChange = false; chart.Dock = DockStyle.Fill; chart.FromDate = project.StartingDate; chart.ToDate = project.DueDate; tableLayoutPanel1.Controls.Add(chart, 0, 0); chart.MouseMove += new MouseEventHandler(chart.GanttChart_MouseMove); chart.MouseMove += new MouseEventHandler(GanttChart1_MouseMove); chart.MouseDragged += new MouseEventHandler(chart.GanttChart_MouseDragged); chart.MouseLeave += new EventHandler(chart.GanttChart_MouseLeave); chart.ContextMenuStrip = ContextMenuGanttChart1; var barInformations = new List <BarInformation>(); var rnd = new Random(); var rowIdx = 0; for (var idx = 0; idx < tasks.Count; ++idx) { var firstColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); var secondColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); if (tasks[idx].IsMilestone) { barInformations.Add(new BarInformation("MileStone " + idx + " : " + tasks[idx].Title, project.StartingDate, tasks[idx].DueDate, firstColor, secondColor, rowIdx++)); } else { barInformations.Add(new BarInformation("Task " + idx + " : " + tasks[idx].Title, tasks[idx].StartingDate, tasks[idx].DueDate, firstColor, secondColor, rowIdx++)); if (!showActualHours || !(tasks[idx].ActualWorkingHours > 0)) { continue; } var ActualWorkingDays = (double)tasks[idx].ActualWorkingHours / 8.0; barInformations.Add(new BarInformation("Task " + idx + " : " + tasks[idx].Title + " (Actual)", tasks[idx].StartingDate, tasks[idx].StartingDate.AddDays(ActualWorkingDays), firstColor, secondColor, rowIdx++)); } } foreach (var bar in barInformations) { chart.AddChartBar(bar.RowText, bar, bar.FromTime, bar.ToTime, bar.Color, bar.HoverColor, bar.Index); } }