/// <summary> /// Draws the appointments of a specified week. /// </summary> private void RenderAppointments(MonthInfo month, IEnumerable <DayInfo> days, SizeF dayCellSize) { const float ImagePadding = 0.02f; for (int week = 0; week < CalendarData.WeeksInMonth; week++) { DateTime weekStartDate = month.GetDateOfDay(week, CalendarData.FirstDayOfWeek, CalendarData.FirstDayOfWeek); DateTime weekEndDate = month.GetDateOfDay(week, CalendarData.LastDayOfWeek, CalendarData.FirstDayOfWeek, true); CalendarData.AppointmentLayoutHelper layoutHelper = new CalendarData.AppointmentLayoutHelper(CalendarData.FirstDayOfWeek, CalendarData.AppointmentGap); foreach (Appointment appointment in CalendarData.GetAppointmentsInWeek(month, week)) { int apptWeekDaysCount = appointment.GetDurationInPeriod(weekStartDate, weekEndDate); Debug.Assert(apptWeekDaysCount > 0, "The appointment should belong to the rendering week."); DateTime appStartDate = appointment.ArrangeStartDate(weekStartDate); DayInfo appStartDayInfo = DayInfo.FindDayInfo(days, appStartDate); Debug.Assert(appStartDayInfo != null, "Day have to be found in the collection."); SizeF appSize = CalendarData.MeasureAppointment(appointment, weekStartDate, weekEndDate, dayCellSize); float appOffset = layoutHelper.Add(appStartDate, appStartDate.AddDays(apptWeekDaysCount - 1), appSize.Height); RectangleF appointmentRect; if (!_rightToLeft) { appointmentRect = new RectangleF( appStartDayInfo.Bounds.X, appStartDayInfo.Bounds.Y + appStartDayInfo.HeaderSize.Height + appOffset, apptWeekDaysCount * dayCellSize.Width, appSize.Height); } else { appointmentRect = new RectangleF( appStartDayInfo.Bounds.X - ((apptWeekDaysCount - 1) * dayCellSize.Width), appStartDayInfo.Bounds.Y + appStartDayInfo.HeaderSize.Height + appOffset, apptWeekDaysCount * dayCellSize.Width, appSize.Height); } AddActionToInteractivityMap(appointment, appointmentRect); using (BrushEx backcolorBrush = Canvas.CreateSolidBrush(appointment.Backcolor)) { Canvas.FillRectangle(backcolorBrush, appointmentRect); } // draw image! Image img = CalendarData.GetAppointmentImage(appointment); RectangleF appTextRect = new RectangleF(appointmentRect.X, appointmentRect.Y, appointmentRect.Width, appointmentRect.Height); bool drawImage = appointment.StartDate >= weekStartDate && appointment.StartDate <= weekEndDate; if (img != null && drawImage) { var imageStream = new MemoryStream(); img.Save(imageStream, ImageFormat.Png); imageStream.Position = 0; using (ImageEx image = Canvas.CreateImage(new ImageInfo(imageStream, "image/png"))) { float imgHeight = Math.Min(CalendarData.GetAppointmentImageSize(appointment), appointmentRect.Width); float imgWidth = imgHeight; float imgLeft; if (!_rightToLeft) { imgLeft = appointmentRect.X; } else { imgLeft = appointmentRect.Right - imgWidth; } float imgTop = appointmentRect.Y + ImagePadding; //Fix for case 44294 Canvas.PushState(); Canvas.IntersectClip(new RectangleF(imgLeft, imgTop, imgWidth, imgHeight)); SizeF imgSz = CalendarData.GetAppointmentImageRealSize(appointment); Canvas.DrawImage(image, imgLeft, imgTop, imgSz.Width, imgSz.Height); Canvas.PopState(); if (imgHeight == appointmentRect.Width) { appTextRect.Y += imgHeight; appTextRect.Height -= imgHeight; } else { if (!_rightToLeft) { appTextRect.X = appointmentRect.X + imgWidth; } appTextRect.Width = appointmentRect.Width - imgWidth; } } } // HACK: we should consider the issue with drawing string later. the issue comes about in the designer when caledar has small width to fit titles. --SergeyP using (StringFormat sf = Components.Calendar.CalendarData.GetAppointmentFormat(appointment, _rightToLeft)) { TextStyle fontStyle = new TextStyle(appointment.FontFamily, appointment.FontSize, appointment.FontStyle, appointment.FontWeight, appointment.FontDecoration, appointment.FontColor); Canvas.PushState(); var font = fontStyle.CreateFontInfo(); using (BrushEx forecolorBrush = Canvas.CreateSolidBrush(fontStyle.FontColor)) { string value = CalendarData.FormatString(appointment.Value, appointment.Format); Canvas.DrawString(value, font, forecolorBrush, appTextRect, ToEx(sf)); } Canvas.PopState(); } LineStyle borderStyle = new LineStyle(appointment.BorderColor); using (PenEx pen = LineStyle.CreatePen(Canvas, borderStyle)) { pen.Width = 1; // HACK: temporary hack because the width is turned off for appointments DrawRectangle(Canvas, pen, appointmentRect.X, appointmentRect.Y, appointmentRect.Width, appointmentRect.Height); } RenderAction(appointment, Canvas, appointmentRect); } } }