protected override void OnPaint(PaintEventArgs e)
            {
                int height = base.ClientSize.Height / 2;

                if (Application.RenderWithVisualStyles)
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer((this.mouseOver == UpDownBase.ButtonID.Up) ? VisualStyleElement.Spin.Up.Hot : VisualStyleElement.Spin.Up.Normal);
                    if (!base.Enabled)
                    {
                        renderer.SetParameters(VisualStyleElement.Spin.Up.Disabled);
                    }
                    else if (this.pushed == UpDownBase.ButtonID.Up)
                    {
                        renderer.SetParameters(VisualStyleElement.Spin.Up.Pressed);
                    }
                    renderer.DrawBackground(e.Graphics, new Rectangle(0, 0, 0x10, height));
                    if (!base.Enabled)
                    {
                        renderer.SetParameters(VisualStyleElement.Spin.Down.Disabled);
                    }
                    else if (this.pushed == UpDownBase.ButtonID.Down)
                    {
                        renderer.SetParameters(VisualStyleElement.Spin.Down.Pressed);
                    }
                    else
                    {
                        renderer.SetParameters((this.mouseOver == UpDownBase.ButtonID.Down) ? VisualStyleElement.Spin.Down.Hot : VisualStyleElement.Spin.Down.Normal);
                    }
                    renderer.DrawBackground(e.Graphics, new Rectangle(0, height, 0x10, height));
                }
                else
                {
                    ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(0, 0, 0x10, height), ScrollButton.Up, (this.pushed == UpDownBase.ButtonID.Up) ? ButtonState.Pushed : (base.Enabled ? ButtonState.Normal : ButtonState.Inactive));
                    ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(0, height, 0x10, height), ScrollButton.Down, (this.pushed == UpDownBase.ButtonID.Down) ? ButtonState.Pushed : (base.Enabled ? ButtonState.Normal : ButtonState.Inactive));
                }
                if (height != ((base.ClientSize.Height + 1) / 2))
                {
                    using (Pen pen = new Pen(this.parent.BackColor))
                    {
                        Rectangle clientRectangle = base.ClientRectangle;
                        e.Graphics.DrawLine(pen, clientRectangle.Left, clientRectangle.Bottom - 1, clientRectangle.Right - 1, clientRectangle.Bottom - 1);
                    }
                }
                base.OnPaint(e);
            }
Beispiel #2
0
 protected override void RenderControl(Graphics g, ButtonState buttonState, CheckState checkState)
 {
     //ControlPaint.DrawScrollButton(g, ClientRectangle, ScrollButton.Up,buttonState);
     ControlPaint.DrawScrollButton(g, ClientRectangle, sButton, buttonState);
 }
Beispiel #3
0
            // Fix: move this into theming API
            private void DrawMonth(Graphics g, DateTime monthDate, CalendarFlags flags)
            {
                UpdateRects(new Point(0, 0), monthDate);
                DateTime today    = DateTime.Today;
                Size     cellSize = parent.cellSize;
                Size     numSize  = parent.numSize;
                Size     textSize = parent.textSize;

                Brush enabledBrush, disabledBrush, lightBrush;

                enabledBrush  = new SolidBrush(SystemColors.ControlText);
                disabledBrush = new SolidBrush(SystemColors.GrayText);
                lightBrush    = new SolidBrush(SystemColors.ControlLight);

                DateTime startDate = new DateTime(monthDate.Year, monthDate.Month, 1);

                hasSelectedItem = false;
                monthStartPos   = -1;
                monthEndPos     = -1;

                // NOTE: why would someone have two different ways of DayOfWeek
                // and Day enums. So for today the weeks starts with sunday

                while (startDate.DayOfWeek != DayOfWeek.Sunday)
                {
                    startDate = startDate.AddDays(-1);
                }

                firstDateCell = startDate;

                g.FillRectangle(lightBrush, titleRect);

                String monthString = monthDate.ToString("MMMM");
                String yearString  = monthDate.ToString("yyyy");

                Font boldFont = new Font(Font, FontStyle.Bold);

                g.DrawString(monthString,
                             boldFont,
                             enabledBrush,
                             monthRect.Left,
                             monthRect.Top,
                             null);

                g.DrawString(yearString,
                             boldFont,
                             enabledBrush,
                             yearRect.Left,
                             yearRect.Top,
                             null);

                DateTime weekStart = firstDateCell;

                for (int i = 0; i < 7; i++)
                {
                    int offset = (cellSize.Width - textSize.Width * 3) / 2;
                    g.DrawString(weekStart.ToString("ddd"),
                                 Font,
                                 disabledBrush,
                                 titleRect.Left + cellSize.Width * i + offset,
                                 titleRect.Bottom,
                                 null);

                    weekStart = weekStart.AddDays(1);
                }
                for (int i = 0; i < 6 * 7; i++)
                {
                    int day = startDate.Day;

                    /* Note: the difference between years cannot be more
                     * than 1 as a MAXIMUM of 7 days will be the difference
                     * between startDate and endDate */
                    int monthRelation = (startDate.Year != monthDate.Year) ?
                                        startDate.Year - monthDate.Year :
                                        startDate.Month - monthDate.Month;

                    Brush b = enabledBrush;

                    if (monthRelation != 0)
                    {
                        b = disabledBrush;
                    }

                    if (monthRelation == 0 && monthStartPos == -1)
                    {
                        monthStartPos = i;
                    }

                    if (monthRelation == 1 && monthEndPos == -1)
                    {
                        monthEndPos = i;
                    }

                    int offset = (cellSize.Width - (day > 9 ? 2 : 1) * numSize.Width) / 2;

                    Rectangle rect = new Rectangle(dayRect.Left + cellSize.Width * (i % 7),
                                                   dayRect.Top + (i / 7) * cellSize.Height,
                                                   cellSize.Width,
                                                   cellSize.Height);

                    if (monthRelation == 0 && startDate >= parent.selectionStart &&
                        startDate <= parent.selectionEnd)
                    {
                        hasSelectedItem = true;
                        g.FillRectangle(lightBrush, rect);
                    }
                    if (monthRelation == 0 && startDate == today)
                    {
                        using (Pen redPen = new Pen(Color.Red, 1.0f))
                        {
                            rect.Size += new Size(-1, 0);
                            g.DrawRectangle(redPen, rect);
                        }
                    }
                    if (monthRelation == 0 ||
                        ((monthRelation < 0) && ((flags & CalendarFlags.ShowLastMonth) != 0)) ||
                        ((monthRelation > 0) && ((flags & CalendarFlags.ShowNextMonth) != 0)))
                    {
                        Font font = IsBolded(startDate) ? boldFont : Font;

                        g.DrawString(day.ToString(),
                                     font,
                                     b,
                                     rect.Left + offset,
                                     rect.Top,
                                     null);
                        posHasDate[i] = true;
                    }
                    else
                    {
                        posHasDate[i] = false;
                    }
                    startDate = startDate.AddDays(1);

                    boldFont.Dispose();

                    if ((flags & CalendarFlags.PrevButton) != 0)
                    {
                        ControlPaint.DrawScrollButton(g,
                                                      prevBtnRect, ScrollButton.Left,
                                                      ButtonState.Flat);
                    }

                    if ((flags & CalendarFlags.NextButton) != 0)
                    {
                        ControlPaint.DrawScrollButton(g,
                                                      nextBtnRect, ScrollButton.Right,
                                                      ButtonState.Flat);
                    }
                }

                lightBrush.Dispose();
                enabledBrush.Dispose();
                disabledBrush.Dispose();
            }