Exemplo n.º 1
0
        private void ResetGraphics()
        {
            graphics.Clear(BackgroundColor);
            graphics.TranslateTransform(this.autoScrollPosition.X, this.autoScrollPosition.Y);

            DayXLocations.Clear();
            TimeXLocations.Clear();
        }
Exemplo n.º 2
0
        private void PopulateDateTimeXLocs(int startX, int endX)
        {
            int      dayDivision = (int)Math.Round((double)(endX - startX) / (EndDate - StartDate).Days);
            int      dayXLoc     = startX;
            DateTime curDay      = StartDate;

            while (curDay < EndDate)
            {
                int dayStart = dayXLoc;
                int dayEnd   = dayXLoc + dayDivision;

                int timeDivision = (int)Math.Round((double)(dayEnd - dayStart) / (EndHourInDay - StartHourInDay));
                int xLoc         = dayStart;
                int curHour      = StartHourInDay;
                while (curHour <= EndHourInDay)
                {
                    DateTime dateWithHour = curDay.AddHours(curHour);

                    if (curHour == StartHourInDay)
                    {
                        StringFormat startFormat = new StringFormat()
                        {
                            Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Far
                        };
                        TimeXLocations.Add(new Tuple <DateTime, int, StringFormat>(dateWithHour, dayStart, startFormat));
                    }
                    else if (curHour == EndHourInDay)
                    {
                        StringFormat endFormat = new StringFormat()
                        {
                            Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Far
                        };
                        TimeXLocations.Add(new Tuple <DateTime, int, StringFormat>(dateWithHour, dayEnd, endFormat));
                    }
                    else
                    {
                        xLoc += timeDivision;
                        StringFormat otherFormat = new StringFormat()
                        {
                            Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far
                        };
                        TimeXLocations.Add(new Tuple <DateTime, int, StringFormat>(dateWithHour, xLoc, otherFormat));
                    }

                    curHour++;
                }

                DayXLocations.Add(new Tuple <DateTime, int, int>(curDay, dayStart, dayEnd));
                dayXLoc = dayEnd;

                curDay = curDay.AddDays(1);
            }
        }
Exemplo n.º 3
0
        private int GetXLocationForDay(DateTime date)
        {
            Tuple <DateTime, int, int> foundGroup = DayXLocations.Find(p => p.Item1 == date.Date);

            if (foundGroup != null)
            {
                return(foundGroup.Item2);
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 4
0
        private void DrawHolidays(int startY, int endY)
        {
            //Don't draw holidays if there are no rows (because the holiday "block" takes up the height of the row)
            if (Rows.Count == 0)
            {
                return;
            }

            foreach (KeyValuePair <DateTime, string> holiday in Holidays)
            {
                //If holiday is not within visible range, don't draw it
                if (holiday.Key < StartDate ||
                    holiday.Key >= EndDate)
                {
                    continue;
                }

                Tuple <DateTime, int, int> dayLocInfo = DayXLocations.Find(p => p.Item1 == holiday.Key.Date);
                if (dayLocInfo != null)
                {
                    Rectangle holidayRect = new Rectangle(dayLocInfo.Item2,
                                                          startY,
                                                          dayLocInfo.Item3 - dayLocInfo.Item2,
                                                          endY - startY);

                    graphics.FillRectangle(new HatchBrush(HatchStyle.ForwardDiagonal, Color.White, Color.DimGray), holidayRect);

                    //Write holiday name
                    if (!string.IsNullOrEmpty(holiday.Value))
                    {
                        Font      holidayNameFont   = new Font(this.font, FontStyle.Bold);
                        Point     holidayRectCenter = new Point(holidayRect.X + holidayRect.Width / 2, startY + 5);
                        int       textWidth         = (int)Math.Round(graphics.MeasureString(holiday.Value, holidayNameFont).Width);
                        int       textHeight        = (int)Math.Round(graphics.MeasureString(holiday.Value, holidayNameFont).Height);
                        Rectangle holidayNameRect   = new Rectangle(holidayRectCenter.X - textWidth / 2 - 2, //"-2" for left margin of 2
                                                                    holidayRectCenter.Y,
                                                                    textWidth + 4,                           //"+4" for right margin of 2 (width also includes left margin)
                                                                    textHeight);

                        graphics.FillRectangle(new SolidBrush(Color.White), holidayNameRect);
                        Point stringLoc = new Point(holidayRectCenter.X, holidayRectCenter.Y + 7);
                        graphics.DrawString(holiday.Value, holidayNameFont, new SolidBrush(Color.Black), stringLoc, alignAllCenter);
                    }
                }
            }
        }