Esempio n. 1
0
        /// <summary>
        /// Draws a box of text
        /// </summary>
        /// <param name="e"></param>
        private void DrawBox(MonthViewBoxEventArgs e)
        {
            if (e.Bounds.Height <= 0 && e.Bounds.Width <= 0)
            {
                return;
            }

            if (!e.BackgroundColor.IsEmpty)
            {
                if (e.BackgroundColor == this._daySelectedBackgroundColor)
                {
                    int r, g, b;
                    r = (int)(e.BackgroundColor.R * 1.1);
                    g = (int)(e.BackgroundColor.G * 1.1);
                    b = (int)(e.BackgroundColor.B * 1.1);
                    Color     c2   = Color.FromArgb(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
                    Rectangle rTop = new Rectangle(new Point(e.Bounds.X, e.Bounds.Y + 1), new Size(e.Bounds.Width, (e.Bounds.Height / 2) + 1));
                    Rectangle rBot = new Rectangle(new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height / 2)), rTop.Size);

                    using (System.Drawing.Drawing2D.LinearGradientBrush gb = new System.Drawing.Drawing2D.LinearGradientBrush(rTop, c2, e.BackgroundColor, 90f))
                    {
                        e.Graphics.FillRectangle(gb, rTop);
                    }
                    using (System.Drawing.Drawing2D.LinearGradientBrush gb = new System.Drawing.Drawing2D.LinearGradientBrush(rBot, e.BackgroundColor, c2, 90f))
                    {
                        e.Graphics.FillRectangle(gb, rBot);
                    }
                }
                else if (e.BackgroundColor == this._monthTitleColor)
                {
                    int r, g, b;
                    r = (int)(e.BackgroundColor.R * 1.07);
                    g = (int)(e.BackgroundColor.G * 1.07);
                    b = (int)(e.BackgroundColor.B * 1.07);
                    Color     c2   = Color.FromArgb(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
                    Rectangle rTop = new Rectangle(new Point(e.Bounds.X, e.Bounds.Y + 1), new Size(e.Bounds.Width, (e.Bounds.Height / 2) + 1));
                    Rectangle rBot = new Rectangle(new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height / 2)), rTop.Size);

                    using (System.Drawing.Drawing2D.LinearGradientBrush gb = new System.Drawing.Drawing2D.LinearGradientBrush(rTop, c2, e.BackgroundColor, 90f))
                    {
                        e.Graphics.FillRectangle(gb, rTop);
                    }
                    using (System.Drawing.Drawing2D.LinearGradientBrush gb = new System.Drawing.Drawing2D.LinearGradientBrush(rBot, e.BackgroundColor, c2, 90f))
                    {
                        e.Graphics.FillRectangle(gb, rBot);
                    }
                }
                else
                {
                    using (SolidBrush b = new SolidBrush(e.BackgroundColor))
                    {
                        e.Graphics.FillRectangle(b, e.Bounds);
                    }
                }
            }

            if (!e.TextColor.IsEmpty && !string.IsNullOrEmpty(e.Text))
            {
                TextRenderer.DrawText(e.Graphics, e.Text, e.Font != null ? e.Font : Font, e.Bounds, e.TextColor, e.TextFlags);
            }

            if (!e.BorderColor.IsEmpty)
            {
                using (Pen p = new Pen(e.BorderColor))
                {
                    Rectangle r = e.Bounds;
                    r.Width--; r.Height--;
                    e.Graphics.DrawRectangle(p, r);
                }
            }
        }
Esempio n. 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.Clear(SystemColors.Window);

            for (int i = 0; i < Months.Length; i++)
            {
                if (Months[i].Bounds.IntersectsWith(e.ClipRectangle))
                {
                    #region MonthTitle

                    string title = Months[i].Date.ToString(MonthTitleFormat);
                    MonthViewBoxEventArgs evtTitle = new MonthViewBoxEventArgs(e.Graphics, Months[i].MonthNameBounds,
                                                                               title,
                                                                               Focused ? MonthTitleTextColor : MonthTitleTextColorInactive,
                                                                               Focused ? MonthTitleColor : MonthTitleColorInactive);

                    DrawBox(evtTitle);

                    #endregion

                    #region DayNames

                    for (int j = 0; j < Months[i].DayNamesBounds.Length; j++)
                    {
                        MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, Months[i].DayNamesBounds[j], Months[i].DayHeaders[j],
                                                                                 StringAlignment.Far, ForeColor, DayBackgroundColor);

                        DrawBox(evtDay);
                    }

                    if (Months[i].DayNamesBounds != null && Months[i].DayNamesBounds.Length != 0)
                    {
                        using (Pen p = new Pen(MonthTitleColor))
                        {
                            int y = Months[i].DayNamesBounds[0].Bottom;
                            e.Graphics.DrawLine(p, new Point(Months[i].Bounds.X, y), new Point(Months[i].Bounds.Right, y));
                        }
                    }
                    #endregion

                    #region Days
                    foreach (MonthViewDay day in Months[i].Days)
                    {
                        if (!day.Visible)
                        {
                            continue;
                        }

                        MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, day.Bounds, day.Date.Day.ToString(),
                                                                                 StringAlignment.Far,
                                                                                 day.Grayed ? DayGrayedText : (day.Selected ? DaySelectedTextColor : ForeColor),
                                                                                 day.Selected ? DaySelectedBackgroundColor : DayBackgroundColor);

                        if (day.Date.Equals(DateTime.Now.Date))
                        {
                            evtDay.BorderColor = TodayBorderColor;
                        }

                        DrawBox(evtDay);
                    }
                    #endregion

                    #region Arrows

                    if (i == 0)
                    {
                        Rectangle r = BackwardButtonBounds;
                        using (Brush b = new SolidBrush(BackwardButtonSelected ? ArrowsSelectedColor : ArrowsColor))
                        {
                            e.Graphics.FillPolygon(b, new Point[] {
                                new Point(r.Right, r.Top + r.Height / 5),
                                new Point(r.Right, (r.Bottom - r.Height / 5) - 1),
                                new Point(r.Left + r.Width / 2, r.Top + r.Height / 2),
                            });
                        }
                    }

                    if (i == _forwardMonthIndex)
                    {
                        Rectangle r = ForwardButtonBounds;
                        using (Brush b = new SolidBrush(ForwardButtonSelected ? ArrowsSelectedColor : ArrowsColor))
                        {
                            e.Graphics.FillPolygon(b, new Point[] {
                                new Point(r.X, r.Top + r.Height / 5),
                                new Point(r.X, (r.Bottom - r.Height / 5) - 1),
                                new Point(r.Left + r.Width / 2, r.Top + r.Height / 2),
                            });
                        }
                    }

                    if (i == 0)
                    {
                        Rectangle r = new Rectangle(BackwardButtonBounds.X - (int)(BackwardButtonBounds.Width * 1.5), BackwardButtonBounds.Y, BackwardButtonBounds.Width, BackwardButtonBounds.Height);
                        using (Brush b = new SolidBrush(FastBackwardButtonSelected ? ArrowsSelectedColor : ArrowsColor))
                        {
                            e.Graphics.FillPolygon(b, new Point[] {
                                new Point(r.Right, r.Top + r.Height / 5),
                                new Point(r.Right, (r.Bottom - r.Height / 5) - 1),
                                new Point(r.Left + r.Width / 2, r.Top + r.Height / 2),
                            });
                        }

                        r = new Rectangle(BackwardButtonBounds.X - BackwardButtonBounds.Width / 2, BackwardButtonBounds.Y, BackwardButtonBounds.Width, BackwardButtonBounds.Height);
                        using (Brush b = new SolidBrush(FastBackwardButtonSelected ? ArrowsSelectedColor : ArrowsColor))
                        {
                            e.Graphics.FillPolygon(b, new Point[] {
                                new Point(r.Right - r.Width / 2, r.Top + r.Height / 5),
                                new Point(r.Right - r.Width / 2, (r.Bottom - r.Height / 5) - 1),
                                new Point(r.Left, r.Top + r.Height / 2),
                            });
                        }
                    }

                    if (i == _forwardMonthIndex)
                    {
                        Rectangle r = new Rectangle(ForwardButtonBounds.X + (int)(ForwardButtonBounds.Width * 1.5), ForwardButtonBounds.Y, ForwardButtonBounds.Width, ForwardButtonBounds.Height);
                        using (Brush b = new SolidBrush(FastForwardButtonSelected ? ArrowsSelectedColor : ArrowsColor))
                        {
                            e.Graphics.FillPolygon(b, new Point[] {
                                new Point(r.X, r.Top + r.Height / 5),
                                new Point(r.X, (r.Bottom - r.Height / 5) - 1),
                                new Point(r.Left + r.Width / 2, r.Top + r.Height / 2),
                            });
                        }
                        r = new Rectangle(ForwardButtonBounds.X + ForwardButtonBounds.Width / 2, ForwardButtonBounds.Y, ForwardButtonBounds.Width, ForwardButtonBounds.Height);
                        using (Brush b = new SolidBrush(FastForwardButtonSelected ? ArrowsSelectedColor : ArrowsColor))
                        {
                            e.Graphics.FillPolygon(b, new Point[] {
                                new Point(r.X + r.Width / 2, r.Top + r.Height / 5),
                                new Point(r.X + r.Width / 2, (r.Bottom - r.Height / 5) - 1),
                                new Point(r.Left + r.Width, r.Top + r.Height / 2),
                            });
                        }
                    }

                    #endregion
                }
            }
        }