public override void OnDrawItemBackground(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBackground(e); var alpha = 255; if (e.Item.IsDragging) { alpha = 120; } else if (e.Calendar.DaysMode == CalendarDaysMode.Short) { alpha = 200; } var color1 = Color.White; var color2 = e.Item.Selected ? ColorTable.ItemSelectedBackground : ColorTable.ItemBackground; if (!e.Item.BackgroundColorLighter.IsEmpty) { color1 = e.Item.BackgroundColorLighter; } if (!e.Item.BackgroundColor.IsEmpty) { color2 = e.Item.BackgroundColor; } ItemFill(e, e.Bounds, Color.FromArgb(alpha, color1), Color.FromArgb(alpha, color2)); }
public override void OnDrawItemBorder(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBorder(e); var a = e.Item.BorderColor.IsEmpty ? ColorTable.ItemBorder : e.Item.BorderColor; var b = e.Item.Selected && !e.Item.IsDragging ? ColorTable.ItemSelectedBorder : a; var c = Color.FromArgb(e.Item.IsDragging ? 120 : 255, b); ItemBorder(e, e.Bounds, c, e.Item.Selected && !e.Item.IsDragging ? SelectedItemBorder : 1f); }
public override void OnDrawItemBorder(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBorder(e); using (var p = new Pen(Color.FromArgb(150, Color.White))) { e.Graphics.DrawLine(p, e.Bounds.Left + ItemRoundness, e.Bounds.Top + 1, e.Bounds.Right - ItemRoundness, e.Bounds.Top + 1); } if (e.Item.Selected && !e.Item.IsDragging) { var horizontal = false; var vertical = false; var r1 = new Rectangle(0, 0, 5, 5); var r2 = new Rectangle(0, 0, 5, 5); horizontal = e.Item.IsOnDayTop; vertical = !e.Item.IsOnDayTop && e.Calendar.DaysMode == CalendarDaysMode.Expanded; if (horizontal) { r1.X = e.Bounds.Left - 2; r2.X = e.Bounds.Right - r1.Width + 2; r1.Y = e.Bounds.Top + (e.Bounds.Height - r1.Height) / 2; r2.Y = r1.Y; } if (vertical) { r1.Y = e.Bounds.Top - 2; r2.Y = e.Bounds.Bottom - r1.Height + 2; r1.X = e.Bounds.Left + (e.Bounds.Width - r1.Width) / 2; r2.X = r1.X; } if ((horizontal || vertical) && Calendar.AllowItemResize) { if (!e.Item.IsOpenStart && e.IsFirst) { e.Graphics.FillRectangle(Brushes.White, r1); e.Graphics.DrawRectangle(Pens.Black, r1); } if (!e.Item.IsOpenEnd && e.IsLast) { e.Graphics.FillRectangle(Brushes.White, r2); e.Graphics.DrawRectangle(Pens.Black, r2); } } } }
public override void OnDrawItemShadow(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemShadow(e); if (e.Item.IsOnDayTop || e.Calendar.DaysMode == CalendarDaysMode.Short || e.Item.IsDragging) { return; } var r = e.Bounds; r.Offset(ItemShadowPadding, ItemShadowPadding); using (var b = new SolidBrush(ColorTable.ItemShadow)) { ItemFill(e, r, ColorTable.ItemShadow, ColorTable.ItemShadow); } }
public override void OnDrawItemBackground(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBackground(e); int alpha = 255; //if (e.Item.IsDragging) //{ // alpha = 120; //} //else if (!e.Item.IsSynchronized) //{ // alpha = 60; //} //else if (e.Calendar.DaysMode == CalendarDaysMode.Short) //{ // alpha = 200; //} Color color1 = Color.White; Color color2 = e.Item.Selected ? ColorTable.ItemSelectedBackground : ColorTable.ItemBackground; if (!e.Item.BackgroundColorLighter.IsEmpty) { color1 = e.Item.BackgroundColorLighter; } if (!e.Item.BackgroundColor.IsEmpty) { color2 = e.Item.BackgroundColor; } if (e.Item.Selected) { ItemFill(e, e.Bounds, ColorTable.SelectedItemBackground, ColorTable.SelectedItemBackground); } else { ItemFill(e, e.Bounds, Color.FromArgb(alpha, color1), Color.FromArgb(alpha, color2)); } }
/// <summary> /// Draws the specified rectangle with item border roundnesss /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="color"></param> /// <param name="width"></param> /// <returns></returns> public void ItemBorder(CalendarRendererItemBoundsEventArgs e, Rectangle bounds, Color color, float width) { using (GraphicsPath r = ItemRectangle(e, bounds)) { using (Pen p = new Pen(color, width)) { e.Graphics.DrawPath(p, r); } } }
public void ItemPattern(CalendarRendererItemBoundsEventArgs e, Rectangle bounds, Color patternColor) { if (bounds.Width <= 0 || bounds.Height <= 0) { return; } using (GraphicsPath r = ItemRectangle(e, bounds)) { using (Brush b = new HatchBrush(e.Item.Pattern, patternColor, Color.Transparent)) { e.Graphics.FillPath(b, r); } } }
/// <summary> /// Fills the specified rectangle with item border roundness /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="north"></param> /// <param name="south"></param> /// <returns></returns> public void ItemFill(CalendarRendererItemBoundsEventArgs e, Rectangle bounds, Color north, Color south) { if (bounds.Width <= 0 || bounds.Height <= 0) { return; } using (GraphicsPath r = ItemRectangle(e, bounds)) { using (LinearGradientBrush b = new LinearGradientBrush(bounds, north, south, 90)) { e.Graphics.FillPath(b, r); } } }
/// <summary> /// Creates a rectangle with item roundess /// </summary> /// <param name="bounds"></param> /// <returns></returns> public GraphicsPath ItemRectangle(CalendarRendererItemBoundsEventArgs evtData, Rectangle bounds) { int pointerPadding = 5; if ((evtData.Item.Bounds.Top != evtData.Item.MinuteStartTop || evtData.Item.Bounds.Bottom != evtData.Item.MinuteEndTop) && (evtData.Item.MinuteEndTop != 0 && evtData.Item.MinuteStartTop != 0) && ! evtData.Item.IsOnDayTop && evtData.Calendar.DaysMode == CalendarDaysMode.Expanded) { /* * Trace pointed item * * C--------------------D * | | * A---B | * | | * H---G | * | | * F--------------------E */ int sq = ItemRoundness * 2; Point a = new Point(bounds.Left, evtData.Item.MinuteStartTop); Point b = new Point(a.X + pointerPadding, a.Y); Point c = new Point(b.X, bounds.Top); Point d = new Point(bounds.Right, c.Y); Point e = new Point(d.X, bounds.Bottom); Point f = new Point(b.X, e.Y); Point g = new Point(b.X, evtData.Item.MinuteEndTop); Point h = new Point(a.X, g.Y); GraphicsPath path = new GraphicsPath(); path.AddLine(a, b); path.AddLine(b, c); path.AddLine(c, new Point(d.X - sq, d.Y)); path.AddArc(new Rectangle(d.X - sq, d.Y, sq, sq), -90, 90); path.AddLine(new Point(d.X, d.Y + sq), new Point(d.X, e.Y - sq)); path.AddArc(new Rectangle(e.X - sq, e.Y - sq, sq, sq), 0, 90); path.AddLine(new Point(e.X - sq, e.Y), f); path.AddLine(f, g); path.AddLine(g, h); path.AddLine(h, a); path.CloseFigure(); return path; } else { Corners crns = Corners.None; if (evtData.IsFirst) { crns |= Corners.West; } if (evtData.IsLast) { crns |= Corners.East; } return RoundRectangle(bounds, ItemRoundness, crns); } }
public override void OnDrawItemShadow(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemShadow(e); if (e.Item.IsOnDayTop || e.Calendar.DaysMode == CalendarDaysMode.Short || e.Item.IsDragging) { return; } Rectangle r = e.Bounds; r.Offset(ItemShadowPadding, ItemShadowPadding); using (SolidBrush b = new SolidBrush(ColorTable.ItemShadow)) { ItemFill(e, r, ColorTable.ItemShadow, ColorTable.ItemShadow); } }
public virtual void OnDrawItemPattern(CalendarRendererItemBoundsEventArgs e) { foreach (Rectangle bounds in e.Item.GetAllBounds()) { ItemPattern(e, bounds, e.Item.PatternColor); } }
/// <summary> /// Draws the background of the specified item /// </summary> /// <param name="e">Event Info</param> public virtual void OnDrawItemBackground(CalendarRendererItemBoundsEventArgs e) { }
/// <summary> /// Draws an item of the calendar /// </summary> /// <param name="e">Event Info</param> public virtual void OnDrawItem(CalendarRendererItemEventArgs e) { List<Rectangle> rects = new List<Rectangle>(e.Item.GetAllBounds()); for (int i = 0; i < rects.Count; i++) { CalendarRendererItemBoundsEventArgs evt = new CalendarRendererItemBoundsEventArgs( e, rects[i], i == 0 && !e.Item.IsOpenStart, (i == rects.Count - 1) && !e.Item.IsOpenEnd); //OnDrawItemShadow(evt); OnDrawItemBackground(evt); if (!evt.Item.PatternColor.IsEmpty) { OnDrawItemPattern(evt); } if (!e.Item.IsEditing) { OnDrawItemContent(evt); } SmoothingMode smbuff = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; OnDrawItemBorder(evt); e.Graphics.SmoothingMode = smbuff; } }
/// <summary> /// Draws the items of the calendar /// </summary> /// <param name="e">Event info</param> public virtual void OnDrawItems(CalendarRendererEventArgs e) { Rectangle days = e.Calendar.DaysBodyRectangle; days.Inflate(-1, -1); Region oldclip = e.Graphics.Clip; bool doClip = e.Calendar.DaysMode == CalendarDaysMode.Expanded; bool clipped = false; #region Shadows foreach (CalendarItem item in e.Calendar.Items) { clipped = false; if (doClip && !item.IsOnDayTop && item.Bounds.Top < days.Top) { e.Graphics.SetClip(days, CombineMode.Intersect); clipped = true; } List<Rectangle> rects = new List<Rectangle>(item.GetAllBounds()); for (int i = 0; i < rects.Count; i++) { CalendarRendererItemBoundsEventArgs evt = new CalendarRendererItemBoundsEventArgs( new CalendarRendererItemEventArgs(e, item), rects[i], i == 0 && !item.IsOpenStart, (i == rects.Count - 1) && !item.IsOpenEnd); OnDrawItemShadow(evt); } if (clipped) e.Graphics.SetClip(oldclip, CombineMode.Replace); } #endregion #region Items foreach (CalendarItem item in e.Calendar.Items) { clipped = false; if (doClip && !item.IsOnDayTop && item.Bounds.Top < days.Top) { e.Graphics.SetClip(days, CombineMode.Intersect); clipped = true; } OnDrawItem(new CalendarRendererItemEventArgs(e, item)); if (clipped) e.Graphics.SetClip(oldclip, CombineMode.Replace); } #endregion #region Borders of selected items foreach (CalendarItem item in e.Calendar.Items) { if (!item.Selected) continue; List<Rectangle> rects = new List<Rectangle>(item.GetAllBounds()); for (int i = 0; i < rects.Count; i++) { CalendarRendererItemBoundsEventArgs evt = new CalendarRendererItemBoundsEventArgs( new CalendarRendererItemEventArgs(e, item), rects[i], i == 0 && !item.IsOpenStart, (i == rects.Count - 1) && !item.IsOpenEnd); SmoothingMode smbuff = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; OnDrawItemBorder(evt); e.Graphics.SmoothingMode = smbuff; } } #endregion }
public override void OnDrawItemBorder(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBorder(e); using (Pen p = new Pen(Color.FromArgb(150, Color.White))) { e.Graphics.DrawLine(p, e.Bounds.Left + ItemRoundness, e.Bounds.Top + 1, e.Bounds.Right - ItemRoundness, e.Bounds.Top + 1); } if (e.Item.Selected && !e.Item.IsDragging) { bool horizontal = false; bool vertical = false; Rectangle r1 = new Rectangle(0, 0, 5, 5); Rectangle r2 = new Rectangle(0, 0, 5, 5); horizontal = e.Item.IsOnDayTop; vertical = !e.Item.IsOnDayTop && e.Calendar.DaysMode == CalendarDaysMode.Expanded; if (horizontal) { r1.X = e.Bounds.Left - 2; r2.X = e.Bounds.Right - r1.Width + 2; r1.Y = e.Bounds.Top + (e.Bounds.Height - r1.Height) / 2; r2.Y = r1.Y; } if (vertical) { r1.Y = e.Bounds.Top - 2; r2.Y = e.Bounds.Bottom - r1.Height + 2; r1.X = e.Bounds.Left + (e.Bounds.Width - r1.Width) / 2; r2.X = r1.X; } if ((horizontal || vertical) && Calendar.AllowItemResize) { if (!e.Item.IsOpenStart && e.IsFirst) { e.Graphics.FillRectangle(Brushes.White, r1); e.Graphics.DrawRectangle(Pens.Black, r1); } if (!e.Item.IsOpenEnd && e.IsLast) { e.Graphics.FillRectangle(Brushes.White, r2); e.Graphics.DrawRectangle(Pens.Black, r2); } } } }
/// <summary> /// Draws the strings of an item. Strings inlude StartTime, EndTime and Text /// </summary> /// <param name="e">Event Info</param> public virtual void OnDrawItemContent(CalendarRendererItemBoundsEventArgs e) { if (e.Item == e.Calendar.EditModeItem) return; List<Rectangle> rectangles = new List<Rectangle>(e.Item.GetAllBounds()); for (int i = 0; i < rectangles.Count; i++) { Rectangle bounds = rectangles[i]; Rectangle imageBounds = Rectangle.Empty; Rectangle rStartTime = new Rectangle(); Rectangle rEndTime = new Rectangle(); string endTime = string.Empty; string startTime = string.Empty; Color secondaryForecolor = e.Item.ForeColor; if (e.Item.ShowEndTime && i == rectangles.Count - 1) { endTime = e.Item.EndDateText; rEndTime = new Rectangle(Point.Empty, TextRenderer.MeasureText(endTime, e.Calendar.Font)); rEndTime = Rectangle.FromLTRB(bounds.Right - rEndTime.Width - ItemTextMargin.Right, bounds.Top + ItemTextMargin.Top, bounds.Right - ItemTextMargin.Right, bounds.Bottom - ItemTextMargin.Bottom); OnDrawItemEndTime(new CalendarRendererBoxEventArgs(e, rEndTime, endTime, secondaryForecolor)); } if (e.Item.ShowStartTime && i == 0) { startTime = e.Item.StartDateText; rStartTime = new Rectangle(Point.Empty, TextRenderer.MeasureText(startTime, e.Calendar.Font)); rStartTime.X = bounds.Left + ItemTextMargin.Left; rStartTime.Y = bounds.Top + ItemTextMargin.Top; rStartTime.Height = bounds.Height - ItemTextMargin.Vertical; OnDrawItemStartTime(new CalendarRendererBoxEventArgs(e, rStartTime, startTime, secondaryForecolor)); } Rectangle r = Rectangle.FromLTRB( bounds.Left + ItemTextMargin.Left + rStartTime.Width, bounds.Top + ItemTextMargin.Top, bounds.Right - ItemTextMargin.Right - rEndTime.Width, bounds.Bottom - ItemTextMargin.Bottom); CalendarRendererBoxEventArgs evt = new CalendarRendererBoxEventArgs(e, r, e.Item.Text, TextFormatFlags.Left | TextFormatFlags.Top); if (e.Item.ShowStartTime || e.Item.ShowEndTime) evt.Font = new Font(evt.Font, FontStyle.Bold); if (e.Item.IsOnDayTop || Calendar.DaysMode == CalendarDaysMode.Short) evt.Format |= TextFormatFlags.HorizontalCenter; if (!e.Item.ForeColor.IsEmpty) { evt.TextColor = e.Item.ForeColor; } evt.Tag = e.Item; #region Image if (e.Item.Image != null) { Rectangle tBounds = e.Item.Bounds; imageBounds.Size = e.Item.Image.Size; switch (e.Item.ImageAlign) { case CalendarItemImageAlign.North: tBounds.Height -= imageBounds.Height; tBounds.Y += imageBounds.Height; imageBounds.Y = tBounds.Y - imageBounds.Height; break; case CalendarItemImageAlign.South: tBounds.Height -= imageBounds.Height; imageBounds.Y = tBounds.Bottom; break; case CalendarItemImageAlign.East: tBounds.Width -= imageBounds.Width; imageBounds.X = tBounds.Right; break; case CalendarItemImageAlign.West: tBounds.Width -= imageBounds.Width; tBounds.X += imageBounds.Width; imageBounds.X = tBounds.Left - imageBounds.Width; break; } switch (e.Item.ImageAlign) { case CalendarItemImageAlign.North: case CalendarItemImageAlign.South: imageBounds.X = e.Item.Bounds.X + ( ( e.Item.Bounds.Width - imageBounds.Width ) / 2); break; case CalendarItemImageAlign.East: case CalendarItemImageAlign.West: imageBounds.Y = e.Item.Bounds.Y + ((e.Item.Bounds.Height - imageBounds.Height) / 2); break; } evt.Bounds = tBounds; OnDrawItemImage(new CalendarRendererItemBoundsEventArgs(e, imageBounds, false, false)); } #endregion OnDrawItemText(evt); } }
/// <summary> /// Draws the image of an item /// </summary> /// <param name="e"></param> public virtual void OnDrawItemImage(CalendarRendererItemBoundsEventArgs e) { if (e.Item.Image != null) { e.Graphics.DrawImage(e.Item.Image, e.Bounds); //e.Graphics.FillRectangle(Brushes.Red, e.Bounds); } }
public override void OnDrawItemBackground(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBackground(e); int alpha = 255; if (e.Item.IsDragging) { alpha = 120; } else if (e.Calendar.DaysMode == CalendarDaysMode.Short) { alpha = 200; } Color color1 = Color.White; Color color2 = e.Item.Selected ? ColorTable.ItemSelectedBackground : ColorTable.ItemBackground; if (!e.Item.BackgroundColorLighter.IsEmpty) { color1 = e.Item.BackgroundColorLighter; } if (!e.Item.BackgroundColor.IsEmpty) { color2 = e.Item.BackgroundColor; } ItemFill(e, e.Bounds, Color.FromArgb(alpha, color1), Color.FromArgb(alpha, color2)); }
/// <summary> /// Draws the shadow of the specified item /// </summary> /// <param name="e"></param> public virtual void OnDrawItemShadow(CalendarRendererItemBoundsEventArgs e) { }
public override void OnDrawItemBorder(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBorder(e); Color a = e.Item.BorderColor.IsEmpty ? ColorTable.ItemBorder : e.Item.BorderColor; Color b = e.Item.Selected && !e.Item.IsDragging ? ColorTable.ItemSelectedBorder : a; Color c = Color.FromArgb(e.Item.IsDragging ? 120 : 255, b); ItemBorder(e, e.Bounds, c, e.Item.Selected && !e.Item.IsDragging ? SelectedItemBorder : 1f); }
/// <summary> /// Draws the border of the specified item /// </summary> /// <param name="e">Event Info</param> public override void OnDrawItemBorder(CalendarRendererItemBoundsEventArgs e) { base.OnDrawItemBorder(e); Color a = e.Item.BorderColor.IsEmpty ? ColorTable.ItemBorder : e.Item.BorderColor; Color b = e.Item.Selected && !e.Item.IsDragging ? ColorTable.ItemSelectedBorder : a; Color c = e.Item.IsDragging ? ColorTable.ItemSelectedBorder : b; float borderWidth = e.Item.Selected && !e.Item.IsDragging ? SelectedItemBorder : 1f; this.ItemBorder(e, e.Bounds, c, borderWidth, e.Item.IsDragging); #region Draw Grab handle using (Pen p = new Pen(Color.FromArgb(150, Color.White))) e.Graphics.DrawLine(p, e.Bounds.Left + ItemRoundness, e.Bounds.Top + 1, e.Bounds.Right - ItemRoundness, e.Bounds.Top + 1); if (e.Item.Selected && !e.Item.IsDragging) { bool horizontal = false; bool vertical = false; Rectangle r1 = new Rectangle(0, 0, 5, 5); Rectangle r2 = new Rectangle(0, 0, 5, 5); horizontal = e.Item.IsOnDayTop || (e.Calendar.DaysMode == DaysModes.Short); vertical = !e.Item.IsOnDayTop && e.Calendar.DaysMode == DaysModes.Expanded; if (horizontal) { r1.X = e.Bounds.Left - 2; r2.X = e.Bounds.Right - r1.Width + 2; r1.Y = e.Bounds.Top + (e.Bounds.Height - r1.Height) / 2; r2.Y = r1.Y; } if (vertical) { r1.Y = e.Bounds.Top - 2; r2.Y = e.Bounds.Bottom - r1.Height + 2; r1.X = e.Bounds.Left + (e.Bounds.Width - r1.Width) / 2; r2.X = r1.X; } if ((horizontal || vertical) && Calendar.AllowItemEdit) { if (!e.Item.IsOpenStart && e.IsFirst) { e.Graphics.FillRectangle(Brushes.White, r1); e.Graphics.DrawRectangle(Pens.Black, r1); } if (!e.Item.IsOpenEnd && e.IsLast) { e.Graphics.FillRectangle(Brushes.White, r2); e.Graphics.DrawRectangle(Pens.Black, r2); } } } #endregion }