Gantt Chart control
상속: System.Windows.Forms.UserControl
예제 #1
0
        public Form1()
        {
            InitializeComponent();
            // create a project manager
            var manager = new ProjectManager();
            // create built-in task or use your own derived task
            var task = new Braincase.GanttChart.Task() { Name = "Hello "};
            var task1 = new Braincase.GanttChart.Task() { Name = " World" };
            var task2 = new Braincase.GanttChart.Task() { Name = "Helly" };
            var task3 = new Braincase.GanttChart.Task() { Name = "Hel7875" };
            var task5 = new Braincase.GanttChart.Task() { Name = "gmmail" };


            // add the task to the manager
            manager.Add(task2);
            manager.Add(task);
            manager.Add(task1);

            manager.Add(task3);
            manager.Split(task2,task1,2);

            
            //manager.SetDuration(task, 3);
            
            // create a chart control
            var chart = new Chart();
            // initialise the chart with the manager
            chart.Init(manager);
            // add chart to the form controls collection.
            this.Controls.Add(chart);
            
            // throughout your own code, call chart.Invalidate()
            // where you expect updates to the drawn chart,
            // to tell the chart to Paint() itself.
        }
        public void InitializeGanttHost()
        {
            _Chart                     = new Braincase.GanttChart.Chart();
            this._Chart.Dock           = System.Windows.Forms.DockStyle.Fill;
            this._Chart.Font           = new System.Drawing.Font("Microsoft JhengHei UI", 8F);
            this._Chart.Location       = new System.Drawing.Point(0, 0);
            this._Chart.Margin         = new System.Windows.Forms.Padding(0);
            this._Chart.Name           = "_Chart";
            this._Chart.Size           = new System.Drawing.Size(671, 496);
            this._Chart.TabIndex       = 0;
            this._Chart.TimeResolution = Braincase.GanttChart.TimeResolution.Day;

            Project1 = new ProjectManager()
            {
                Start = new DateTime(2018, 11, 1)
            };
            var task1 = new MyTask(Project1)
            {
                Name = "Project 1"
            };
            var task2 = new MyTask(Project1)
            {
                Name = "Task 1"
            };
            var task3 = new MyTask(Project1)
            {
                Name = "Task 2"
            };
            var task4 = new MyTask(Project1)
            {
                Name = "Task 3"
            };
            var task5 = new MyTask(Project1)
            {
                Name = "Task 4"
            };
            var task6 = new MyTask(Project1)
            {
                Name = "Task 5"
            };
            var task7 = new MyTask(Project1)
            {
                Name = "Task 6"
            };

            Project1.Add(task1);
            Project1.Add(task2);
            Project1.Add(task3);
            Project1.Add(task4);
            Project1.Add(task5);
            Project1.Add(task6);
            Project1.Add(task7);
            Project1.SetDuration(task1, TimeSpan.FromDays(3));
            Project1.SetDuration(task2, TimeSpan.FromDays(5));
            Project1.SetDuration(task3, TimeSpan.FromDays(7));
            Project1.SetDuration(task4, TimeSpan.FromDays(4));
            Project1.SetDuration(task5, TimeSpan.FromDays(3));
            Project1.SetDuration(task6, TimeSpan.FromDays(5));
            Project1.Group(task1, task2);
            Project1.Group(task1, task3);
            Project1.Group(task1, task4);
            Project1.Group(task1, task5);
            Project1.Group(task1, task6);
            Project1.Group(task1, task7);
            Project1.Relate(task2, task3);
            Project1.Relate(task2, task4);
            Project1.Relate(task4, task5);
            Project1.Relate(task4, task6);
            Project1.Relate(task6, task7);
            Project1.Relate(task5, task7);

            var span = DateTime.Today - Project1.Start;

            Project1.Now = span;
            Projects.Add(Project1);

            Project1 = new ProjectManager()
            {
                Start = new DateTime(2018, 11, 16)
            };
            task1 = new MyTask(Project1)
            {
                Name = "Project 2"
            };
            task2 = new MyTask(Project1)
            {
                Name = "Task 1"
            };
            task3 = new MyTask(Project1)
            {
                Name = "Task 2"
            };
            task4 = new MyTask(Project1)
            {
                Name = "Task 3"
            };
            task5 = new MyTask(Project1)
            {
                Name = "Task 4"
            };
            task6 = new MyTask(Project1)
            {
                Name = "Task 5"
            };
            task7 = new MyTask(Project1)
            {
                Name = "Task 6"
            };
            Project1.Add(task1);
            Project1.Add(task2);
            Project1.Add(task3);
            Project1.Add(task4);
            Project1.Add(task5);
            Project1.Add(task6);
            Project1.Add(task7);
            Project1.SetDuration(task7, TimeSpan.FromDays(4));
            Project1.SetDuration(task2, TimeSpan.FromDays(5));
            Project1.SetDuration(task3, TimeSpan.FromDays(12));
            Project1.SetDuration(task4, TimeSpan.FromDays(6));
            Project1.SetDuration(task5, TimeSpan.FromDays(3));
            Project1.SetDuration(task6, TimeSpan.FromDays(8));
            Project1.Group(task1, task2);
            Project1.Group(task1, task3);
            Project1.Group(task1, task4);
            Project1.Group(task1, task5);
            Project1.Group(task1, task6);
            Project1.Group(task1, task7);
            Project1.Relate(task2, task3);
            Project1.Relate(task2, task4);
            Project1.Relate(task2, task5);
            Project1.Relate(task4, task6);
            Project1.Relate(task3, task7);
            Project1.Relate(task5, task7);

            span         = DateTime.Today - Project1.Start;
            Project1.Now = span;
            Projects.Add(Project1);

            Project1 = new ProjectManager()
            {
                Start = new DateTime(2018, 10, 26)
            };
            task1 = new MyTask(Project1)
            {
                Name = "Project 3"
            };
            task2 = new MyTask(Project1)
            {
                Name = "Task 1"
            };
            task3 = new MyTask(Project1)
            {
                Name = "Task 2"
            };
            task4 = new MyTask(Project1)
            {
                Name = "Task 3"
            };
            task5 = new MyTask(Project1)
            {
                Name = "Task 4"
            };
            task6 = new MyTask(Project1)
            {
                Name = "Task 5"
            };
            task7 = new MyTask(Project1)
            {
                Name = "Task 6"
            };
            var task8 = new MyTask(Project1)
            {
                Name = "Task 7"
            };

            Project1.Add(task1);
            Project1.Add(task2);
            Project1.Add(task3);
            Project1.Add(task4);
            Project1.Add(task5);
            Project1.Add(task6);
            Project1.Add(task7);
            Project1.Add(task8);
            Project1.SetDuration(task2, TimeSpan.FromDays(5));
            Project1.SetDuration(task3, TimeSpan.FromDays(12));
            Project1.SetDuration(task4, TimeSpan.FromDays(6));
            Project1.SetDuration(task5, TimeSpan.FromDays(3));
            Project1.SetDuration(task6, TimeSpan.FromDays(8));
            Project1.SetDuration(task7, TimeSpan.FromDays(12));
            Project1.SetDuration(task8, TimeSpan.FromDays(18));
            Project1.Group(task1, task2);
            Project1.Group(task1, task3);
            Project1.Group(task1, task4);
            Project1.Group(task1, task5);
            Project1.Group(task1, task6);
            Project1.Group(task1, task7);
            Project1.Relate(task2, task4);
            Project1.Relate(task2, task6);
            Project1.Relate(task2, task5);
            Project1.Relate(task4, task6);
            Project1.Relate(task3, task7);
            Project1.Relate(task5, task8);

            span         = DateTime.Today - Project1.Start;
            Project1.Now = span;
            Projects.Add(Project1);


            //_Chart.Init(Project1);

            //_Chart.CreateTaskDelegate = delegate () { return new MyTask(Project1); };
            this.GanttHost.Child           = _Chart;
            TimeViewComboBox.ItemsSource   = typeof(TimeResolution).GetEnumNames();
            TimeViewComboBox.SelectedIndex = 1;

            foreach (var p in Projects.ToList())
            {
                ProjectNames.Add(p.Tasks.FirstOrDefault());
            }
            ProjectsComboBox.ItemsSource = ProjectNames.ToList();
        }