private int _DrawTasks(Graphics graphics, Rectangle clipRect)
        {
            var   viewRect    = _mViewport.Rectangle;
            int   row         = 0;
            var   pen         = new Pen(Color.Gray);
            float labelMargin = this.MinorWidth / 2.0f + 3.0f;

            pen.DashStyle = DashStyle.Dot;
            TaskPaintEventArgs e;

            foreach (var task in _mChartTaskRects.Keys)
            {
                // Get the taskrect
                var taskrect = _mChartTaskRects[task];
                // Only begin drawing when the taskrect is to the left of the clipRect's right edge
                if (taskrect.Left <= viewRect.Right)
                {
                    e = new TaskPaintEventArgs(graphics, clipRect, this, task, row, this.Font, task.Format);
                    PaintTask?.Invoke(this, e);

                    if (viewRect.IntersectsWith(taskrect))
                    {
                        __DrawRegularTaskAndGroup(graphics, e, task, taskrect);
                    }

                    // write text
                    if (this.ShowTaskLabels && task.Name != string.Empty)
                    {
                        var name    = task.Name;
                        var txtrect = graphics.TextBoxAlign(name, ChartTextAlign.MiddleLeft, e.Font, taskrect, labelMargin);
                        txtrect.Offset(taskrect.Width, 0);
                        if (viewRect.IntersectsWith(txtrect))
                        {
                            graphics.DrawString(name, e.Font, e.Format.Color, txtrect);
                        }
                    }

                    // draw slack
                    if (this.ShowSlack)
                    {
                        var slackrect = _mChartSlackRects[task];
                        if (viewRect.IntersectsWith(slackrect))
                        {
                            graphics.FillRectangle(e.Format.SlackFill, slackrect);
                        }
                    }
                }
                row++;
            }
            return(row);
        }
        private int DrawScheduleEvents(Graphics graphics, SchedulerModels models, Rectangle clipRect)
        {
            var   viewRect    = viewport.Rectangle;
            var   pen         = new Pen(Color.Gray);
            float labelMargin = control.MinorWidth / 2.0f + 3.0f;

            pen.DashStyle = DashStyle.Dot;
            TaskPaintEventArgs e;

            foreach (var task in models.EventRectangles.Keys)
            {
                // Get the taskrect
                var taskrect = models.EventRectangles[task];
                // Only begin drawing when the taskrect is to the left of the clipRect's right edge
                if (taskrect.Left <= viewRect.Right)
                {
                    e = new TaskPaintEventArgs(graphics, clipRect, control, task, task.Row, control.Font, task.Format);
                    PaintTask?.Invoke(control, e);

                    if (viewRect.IntersectsWith(taskrect))
                    {
                        DrawScheduleEvent(graphics, e, task, taskrect);
                    }

                    // write text
                    if (control.ShowTaskLabels && task.Name != string.Empty)
                    {
                        var name    = task.Name;
                        var txtrect = graphics.TextBoxAlign(name, ChartTextAlign.MiddleLeft, e.Font, taskrect, labelMargin);
                        txtrect.Offset(taskrect.Width, 0);
                        if (viewRect.IntersectsWith(txtrect))
                        {
                            graphics.DrawString(name, e.Font, e.Format.Color, txtrect);
                        }
                    }

                    // draw slack
                    if (control.ShowSlack)
                    {
                        var slackrect = models.EventSlackRectangles[task];
                        if (viewRect.IntersectsWith(slackrect))
                        {
                            graphics.FillRectangle(e.Format.SlackFill, slackrect);
                        }
                    }
                }
            }
            return(1);
        }