public TaskScheduler AddTaskScheduler() { TaskScheduler task = new TaskScheduler(this); ProgressList.Add(task); ProgressItem item = new ProgressItem(); item.Minimum = 0; item.Maximum = 100000; item.Visible = false; ProgressControls.Add(task, item); task.OnUpdate += new Action <TaskScheduler, string, string, double>(Progress_OnUpdate); task.OnError += new Action <TaskScheduler, ProgressException>(Progress_OnError); return(task); }
void Progress_OnUpdate_Base(TaskScheduler task, string rootstatus, string status, double percent) { ProgressItem item = ProgressControls[task]; if (rootstatus == null && status == null && percent == 0) { item.Visible = false; if (item.Parent != null) { item.Parent.Controls.Remove(item); } AutoManageTasks(); return; } else if (item.Visible == false) { item.Visible = true; ProgressLayout.Controls.Add(item); item.Dock = DockStyle.Fill; AutoManageTasks(); } long progress; long max; task.Progress.GetTask(out progress, out max); string taskprogress = string.Empty; if (max > 1) { taskprogress = "[" + (progress + 1).ToString() + " / " + max.ToString() + "] "; } item.Text = taskprogress + rootstatus; item.ToolTipText = status; item.Value = (int)(percent * (double)item.Maximum); AutoResizeTasks(); }
private void AutoResizeTasks() { if (ProgressLayout.Controls.Count == 0) { ProgressLayout.Width = 0; ProgressLayout.Height = 0; ProgressLayout.Visible = false; return; } int cumulativewidth = 0; for (int x = 0; x < ProgressLayout.ColumnCount; x++) { int width = 0; for (int y = 0; y < ProgressLayout.RowCount; y++) { ProgressItem item = ProgressLayout.GetControlFromPosition(x, y) as ProgressItem; if (item == null) { continue; } if (item.PreferredWidth > width) { width = item.PreferredWidth; } } ProgressLayout.ColumnStyles[x].Width = width; cumulativewidth += width + 3; } cumulativewidth += 3; if (ProgressLayout.Width != cumulativewidth) { ProgressLayout.Width = cumulativewidth; } }