private void sfCalendarDrawCell(SfCalendar sender, Syncfusion.WinForms.Input.Events.DrawCellEventArgs args)
        {
            args.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            if (args.IsTrailingDate)
            {
                args.ForeColor = Color.DarkGray;
            }


            //ensure a date is selected
            if (!args.Value.HasValue)
            {
                return;
            }

            DateTime here = args.Value.Value;

            var drawList = getDrawListForDay(here);

            int startPosition = 0;

            foreach (var task in drawList)
            {
                args.Handled = true;

                Color c = args.IsTrailingDate ? Color.DarkGray : Color.Black;

                TextRenderer.DrawText(args.Graphics, args.Value.Value.Day.ToString(), new Font("Segoe UI", 10, System.Drawing.FontStyle.Regular), args.CellBounds, c, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);

                args.Graphics.FillRectangle(new SolidBrush(task.DrawColor), new System.Drawing.Rectangle((args.CellBounds.X + (args.CellBounds.Width - args.CellBounds.Width / 2)) - (drawList.Count * 2) - (drawList.Count * 6) - startPosition, (args.CellBounds.Y + (args.CellBounds.Height - 20)), 13, 13));
                startPosition -= 18;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Event helps to customize the Cell.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void SfCalendar1_DrawCell1(Syncfusion.WinForms.Input.SfCalendar sender, Syncfusion.WinForms.Input.Events.DrawCellEventArgs args)
        {
            if (!args.Value.HasValue)
            {
                return;
            }
            Image image = null;

            if (args.ViewType == Syncfusion.WinForms.Input.Enums.CalendarViewType.Year && args.Value.Value.Month == new DateTime(2018, 12, 25).Month&& args.Value.Value.Year == new DateTime(2018, 12, 25).Year)
            {
                args.Handled = true;
                image        = Properties.Resources.Icon_Christmas_day;
                args.Graphics.DrawImage(image, args.CellBounds);
            }

            if (args.ViewType == Syncfusion.WinForms.Input.Enums.CalendarViewType.Year && args.Value.Value.Month == new DateTime(2018, 02, 14).Month&& args.Value.Value.Year == new DateTime(2018, 02, 14).Year)
            {
                args.Handled = true;
                image        = Properties.Resources.Icon_Valentines_day;
                args.Graphics.DrawImage(image, args.CellBounds);
            }
            if (args.ViewType == Syncfusion.WinForms.Input.Enums.CalendarViewType.Year && args.Value.Value.Month == new DateTime(2018, 07, 1).Month&& args.Value.Value.Year == new DateTime(2018, 07, 1).Year)
            {
                args.Handled = true;
                image        = Properties.Resources.Icon_Doctor_s_Day;
                args.Graphics.DrawImage(image, args.CellBounds);
            }
            if (args.ViewType == Syncfusion.WinForms.Input.Enums.CalendarViewType.Year && args.Value.Value.Month == new DateTime(2018, 09, 25).Month&& args.Value.Value.Year == new DateTime(2018, 09, 25).Year)
            {
                args.Handled = true;
                image        = Properties.Resources.Icon_Engineers_day;
                args.Graphics.DrawImage(image, args.CellBounds);
            }
            if (args.ViewType == Syncfusion.WinForms.Input.Enums.CalendarViewType.Month)
            {
                args.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                int         startPosition = 0;
                Appointment appointment   = this.Appointment.Find(
                    delegate(Appointment bk)
                {
                    return((bk.Date.Day == args.Value.Value.Date.Day) && (bk.Date.Month == args.Value.Value.Date.Month) && (bk.Date.Year == args.Value.Value.Date.Year));
                }
                    );
                if (appointment != null && (args.Value.Value.DayOfWeek != DayOfWeek.Sunday))
                {
                    args.Handled = true;
                    {
                        if (args.IsTrailingDate)
                        {
                            for (int j = 0; j < appointment.Appointments.Count; j++)
                            {
                                args.Graphics.FillRectangle(new SolidBrush(ControlPaint.LightLight(appointment.Appointments[j].AppointmentColor)), new Rectangle((args.CellBounds.X + (args.CellBounds.Width - args.CellBounds.Width / 2)) - (appointment.Appointments.Count * 2) - (appointment.Appointments.Count * 6) - startPosition, (args.CellBounds.Y + (args.CellBounds.Height - 20)), 12, 12));
                                startPosition -= 18;
                            }
                            TextRenderer.DrawText(args.Graphics, args.Value.Value.Day.ToString(), new Font("Segoe UI", this.sfCalendar1.Style.Cell.CellFont.Size), args.CellBounds, ControlPaint.LightLight(Color.IndianRed), TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                        }
                        else
                        {
                            for (int j = 0; j < appointment.Appointments.Count; j++)
                            {
                                args.Graphics.FillRectangle(new SolidBrush(appointment.Appointments[j].AppointmentColor), new Rectangle((args.CellBounds.X + (args.CellBounds.Width - args.CellBounds.Width / 2)) - (appointment.Appointments.Count * 2) - (appointment.Appointments.Count * 6) - startPosition, (args.CellBounds.Y + (args.CellBounds.Height - 20)), 12, 12));
                                startPosition -= 18;
                            }
                            TextRenderer.DrawText(args.Graphics, args.Value.Value.Day.ToString(), new Font("Segoe UI", this.sfCalendar1.Style.Cell.CellFont.Size), args.CellBounds, Color.IndianRed, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                        }
                    }
                }
                else
                {
                    args.Handled = true;
                    if (!args.IsTrailingDate)
                    {
                        TextRenderer.DrawText(args.Graphics, args.Value.Value.Day.ToString(), new Font("Segoe UI", this.sfCalendar1.Style.Cell.CellFont.Size), args.CellBounds, this.sfCalendar1.Style.Cell.CellForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                    }
                    else
                    {
                        TextRenderer.DrawText(args.Graphics, args.Value.Value.Day.ToString(), new Font("Segoe UI", this.sfCalendar1.Style.Cell.CellFont.Size), args.CellBounds, ControlPaint.LightLight(this.sfCalendar1.Style.Cell.TrailingCellForeColor), TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                    }
                }
            }
        }