Beispiel #1
0
        /// <summary>
        /// Raises the <see cref="E:Paint"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            //paint month name header
            RendererCache.Current.BigHeader.DrawBox(e.Graphics, Font, monthHeader.Bounds, monthHeader.Name, true, BorderInfo.Default, TextAlignment.Center, true);

            //calculate the appointment heights
            int apptHeight = RendererCache.Current.Appointment.GetTextInfo(e.Graphics, Font).Height + 2;

            foreach (HeaderRegion head in this.headers)
            {
                RendererCache.Current.Header.DrawBox(e.Graphics, Font, head.Bounds, head.Name);
            }
            foreach (DayRegion day in this.days)
            {
                if (day.IsInCurrentMonth)
                {
                    //paint day box
                    RendererCache.Current.Item.DrawBox(e.Graphics, Font, day.Bounds);
                    //paint day box header
                    RendererCache.Current.Item.DrawBox(e.Graphics, Font, day.TitleBounds, string.Format("{0}", day.Date.Day), true, BorderInfo.None);

                    //TODO: Move the appointment bounds calc to CalculateAppointmentBounds

                    //calculate how many appointments can be visible at once
                    int maxAppts = 0;
                    if (day.BodyBounds.Height > apptHeight)
                    {
                        maxAppts = day.BodyBounds.Height / apptHeight;
                    }
                    //figure out if we'll need scrolling
                    bool useScrolling = day.Appointments.Count > maxAppts;

                    //decided to use columns for no reason - this could be done with scrolling, probably be better
                    int columnCount = 1;
                    if (maxAppts > 0)
                    {
                        columnCount = day.Appointments.Count / maxAppts;
                        if (day.Appointments.Count % maxAppts > 0)
                        {
                            columnCount++;
                        }
                    }
                    int currentColumn = 0;
                    int columnWidth   = day.TitleBounds.Width;
                    if (columnCount > 0)
                    {
                        columnWidth = day.TitleBounds.Width / columnCount;
                    }


                    //paint the appointments
                    int yPosition = day.Bounds.Y + day.TitleBounds.Height;
                    int xPosition = day.Bounds.X;
                    AppointmentRegion paintSelected = null;
                    foreach (AppointmentRegion app in day.Appointments)
                    {
                        //render next column
                        if (yPosition + apptHeight > day.BodyBounds.Y + day.BodyBounds.Height)
                        {
                            currentColumn++;
                            xPosition = xPosition + columnWidth;
                            yPosition = day.BodyBounds.Y;
                        }

                        //if any of these fit on the screen
                        if (yPosition + apptHeight < day.Bounds.Y + day.Bounds.Height)
                        {
                            app.Bounds = new Rectangle(xPosition, yPosition, columnWidth, apptHeight);
                            if (app.Appointment == SelectedAppointment)
                            {
                                paintSelected = app;
                            }
                            else
                            {
                                RendererCache.Current.Appointment.DrawBox(e.Graphics, Font, app.BodyBounds, app.FormattedSubject);
                                if (app.ColourBlockBounds != Rectangle.Empty)
                                {
                                    RendererCache.Current.Appointment.DrawBox(e.Graphics, Font, app.ColourBlockBounds, app.Appointment.ColorBlockBrush);
                                }
                            }
                            yPosition += apptHeight;
                        }
                    }

                    // repaint just the selected appointment - to get the border onto it even with overlap
                    if (paintSelected != null)
                    {
                        RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.BodyBounds, paintSelected.FormattedSubject);
                        if (paintSelected.ColourBlockBounds != Rectangle.Empty)
                        {
                            RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.ColourBlockBounds, paintSelected.Appointment.ColorBlockBrush);

                            //draw top and bottom blocks
                            RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.SelectTopBounds, paintSelected.Appointment.ColorBlockBrush);
                            RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.SelectBottomBounds, paintSelected.Appointment.ColorBlockBrush);
                        }
                    }
                }
                else
                {
                    //non working days are dark
                    RendererCache.Current.Control.DrawBox(e.Graphics, Font, day.Bounds);
                    //paint day box header
                    RendererCache.Current.Control.DrawBox(e.Graphics, Font, day.TitleBounds, string.Format("{0}", day.Date.Day), true, BorderInfo.None);
                }
            }

            //TODO: scrolling
        }
        /// <summary>
        /// Raises the <see cref="E:Paint"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            //paint hour headers
            foreach (HeaderRegion header in hourHeaders)
            {
                RendererCache.Current.Header.DrawBox(e.Graphics, Font, header.Bounds, header.Name, true, BorderInfo.Default, TextAlignment.Right);
            }

            for (int j = 0; j < DayRegions.Count; j++)
            {
                DayWithHourRegion day = DayRegions[j] as DayWithHourRegion;
                if (day != null)
                {
                    //paint header
                    RendererCache.Current.Header.DrawBox(e.Graphics, Font, day.TitleBounds, day.Name);

                    foreach (HourRegion hour in day.Hours)
                    {
                        if (hour.IsWorkingHour)
                        {
                            RendererCache.Current.Item.DrawBox(e.Graphics, Font, hour.Bounds);
                            RendererCache.Current.ItemLight.DrawLine(e.Graphics, hour.Bounds30.X + 1, hour.Bounds30.Y,
                                                                     hour.Bounds30.X + hour.Bounds30.Width - 2,
                                                                     hour.Bounds30.Y);
                        }
                        else
                        {
                            //non working hours are dark
                            RendererCache.Current.Control.DrawBox(e.Graphics, Font, hour.Bounds);
                        }
                    }
                    foreach (HourRegion hour in day.Hours)
                    {
                        AppointmentRegion paintSelected = null;
                        // int yPosition = hour.Bounds.Y;
                        foreach (AppointmentWithHourRegion app in hour.Appointments)
                        {
                            if (app.Appointment == SelectedAppointment)
                            {
                                paintSelected = app;
                            }
                            else
                            {
                                RendererCache.Current.Appointment.DrawBox(e.Graphics, Font, app.BodyBounds, app.FormattedSubject);
                                if (app.ColourBlockBounds != Rectangle.Empty)
                                {
                                    RendererCache.Current.Appointment.DrawBox(e.Graphics, Font, app.ColourBlockBounds, app.Appointment.ColorBlockBrush);
                                }
                            }
                        }

                        // repaint just the selected appointment - to get the border onto it even with overlap
                        if (paintSelected != null)
                        {
                            RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.BodyBounds, paintSelected.FormattedSubject);
                            if (paintSelected.ColourBlockBounds != Rectangle.Empty)
                            {
                                RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.ColourBlockBounds, paintSelected.Appointment.ColorBlockBrush);


                                //draw top and bottom blocks
                                RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.SelectTopBounds, paintSelected.Appointment.ColorBlockBrush);
                                RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.SelectBottomBounds, paintSelected.Appointment.ColorBlockBrush);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Raises the <see cref="E:Paint"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            int apptHeight = RendererCache.Current.Appointment.GetTextInfo(e.Graphics, Font).Height + 2;

            //paint the days
            foreach (DayRegion day in this.Days)
            {
                //render if we can fit
                if (fontHeight < Bounds.Height)
                {
                    if (day == SelectedSlot)
                    {
                        RendererCache.Current.HeaderSelected.DrawBox(e.Graphics, Font, day.TitleBounds, day.FormattedName);
                    }
                    else
                    {
                        RendererCache.Current.Header.DrawBox(e.Graphics, Font, day.TitleBounds, day.FormattedName);
                    }
                    //paint the body
                    RendererCache.Current.Item.DrawBox(e.Graphics, Font, day.BodyBounds);

                    //TODO: Move the appointment width calc to CalculateAppointmentBounds

                    //calculate how many appointments can be visible at once
                    int maxAppts = 0;
                    if (day.BodyBounds.Height > apptHeight)
                    {
                        maxAppts = day.BodyBounds.Height / apptHeight;
                    }
                    //figure out if we'll need scrolling
                    bool useScrolling = day.Appointments.Count > maxAppts;

                    //decided to use columns for no reason - this could be done with scrolling, probably be better
                    int columnCount = 1;
                    if (maxAppts > 0)
                    {
                        columnCount = day.Appointments.Count / maxAppts;
                        if (day.Appointments.Count % maxAppts > 0)
                        {
                            columnCount++;
                        }
                    }
                    int currentColumn = 0;
                    int columnWidth   = day.TitleBounds.Width;
                    if (columnCount > 0)
                    {
                        columnWidth = day.TitleBounds.Width / columnCount;
                    }

                    //paint the appointments
                    int yPosition = day.BodyBounds.Y;
                    int xPosition = day.BodyBounds.X;
                    AppointmentRegion paintSelected = null;
                    foreach (AppointmentRegion app in day.Appointments)
                    {
                        if (yPosition + apptHeight > day.BodyBounds.Y + day.BodyBounds.Height)
                        {
                            currentColumn++;
                            xPosition = xPosition + columnWidth;
                            yPosition = day.BodyBounds.Y;
                        }

                        //if (yPosition + apptHeight < day.BodyBounds.Y + day.BodyBounds.Height)
                        //{
                        app.Bounds = new Rectangle(xPosition, yPosition, columnWidth, apptHeight);

                        if (app.Appointment == SelectedAppointment)
                        {
                            paintSelected = app;
                        }
                        else
                        {
                            RendererCache.Current.Appointment.DrawBox(e.Graphics, Font, app.BodyBounds, app.FormattedSubject);
                            if (app.ColourBlockBounds != Rectangle.Empty)
                            {
                                RendererCache.Current.Appointment.DrawBox(e.Graphics, Font, app.ColourBlockBounds, app.Appointment.ColorBlockBrush);
                            }
                        }
                        yPosition += apptHeight;
                        //}
                    }

                    // repaint just the selected appointment - to get the border onto it even with overlap
                    if (paintSelected != null)
                    {
                        RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.BodyBounds, paintSelected.FormattedSubject);
                        if (paintSelected.ColourBlockBounds != Rectangle.Empty)
                        {
                            RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.ColourBlockBounds, paintSelected.Appointment.ColorBlockBrush);


                            //draw top and bottom blocks
                            RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.SelectTopBounds, paintSelected.Appointment.ColorBlockBrush);
                            RendererCache.Current.AppointmentSelected.DrawBox(e.Graphics, Font, paintSelected.SelectBottomBounds, paintSelected.Appointment.ColorBlockBrush);
                        }
                    }
                }
            }
        }