示例#1
0
        private void ResizeDayLabels(object sender, CalendarResizedEventArgs e)
        {
            // set position and width for each day label upon repaint
            for (int i = 0; i < e.dayStartPositions.Length - 1; i++)
            {
                dayLabels[i].Left  = e.dayStartPositions[i];
                dayLabels[i].Width = e.dayStartPositions[i + 1] - e.dayStartPositions[i] + 1;
            }

            if (weekView)
            {
                // hide day change button for week view
                leftDayButton.Visible  = false;
                rightDayButton.Visible = false;
            }
            else
            {
                // show day change buttons for day view
                rightDayButton.Left    = e.dayStartPositions[0] + selectedDayLabel.Width + 60;
                rightDayButton.Visible = true;
                leftDayButton.Left     = e.dayStartPositions[0] - 60 - rightDayButton.Width;
                leftDayButton.Visible  = true;
            }
        }
示例#2
0
        /// <summary>
        /// Draw the day/hour grid and hour labels for the frame of the calendar
        /// </summary>
        /// <param name="pe">PaintEventArgs for drawing graphics on the control</param>
        public void DrawCalendarFrame(PaintEventArgs pe)
        {
            int width  = this.ClientRectangle.Width - leftMargin - rightMargin;
            int height = 1920;
            int left   = this.ClientRectangle.Left + leftMargin;
            int top    = this.ClientRectangle.Top + topMargin;
            int right  = left + width;
            int bottom = top + height;

            // fire the resize event with the needed positions for the day dividers
            CalendarResizedEventArgs r = new CalendarResizedEventArgs
            {
                dayStartPositions = new int[] { left, left + width / 5, left + 2 * width / 5, left + 3 * width / 5, left + 4 * width / 5, right },
            };

            ResizeEvent?.Invoke(this, r);

            Pen pen = new Pen(Color.LightGray);

            // draw horizontal divider lines of calendar
            int startX;

            for (int i = 0; i < 48; i++)
            {
                if (i % 2 == 0)
                {
                    startX = 0;
                }
                else
                {
                    startX = leftMargin;
                }
                pe.Graphics.DrawLine(pen, new Point(startX, top + 40 * i), new Point(right, top + 40 * i));
            }

            pen.Color = Color.Black;

            // draw vertical divider lines of calendar
            pe.Graphics.DrawLine(pen, new Point(left, top), new Point(left, bottom));                      // left vertical border line
            pe.Graphics.DrawLine(pen, new Point(left + width / 5, top), new Point(left + width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 2 * width / 5, top), new Point(left + 2 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 3 * width / 5, top), new Point(left + 3 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 4 * width / 5, top), new Point(left + 4 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(right, top), new Point(right, bottom));                    // right vertical border line

            // draw bottom border line
            pen.Width *= 2;
            pe.Graphics.DrawLine(pen, new Point(left, bottom), new Point(right, bottom));

            // finished with pen for drawing, so dispose
            pen.Dispose();

            // prepare to draw hour divider labels (using SolidBrush)
            System.Drawing.Font         drawFont   = new System.Drawing.Font("Segoe UI", 12);
            System.Drawing.SolidBrush   brush      = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
            System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();

            // draw label for each hour
            for (int i = 0; i < 24; i++)
            {
                pe.Graphics.DrawString(GetHourLabel(i), drawFont, brush, 5, top + 80 * i, drawFormat);
            }

            // dispose of string drawing resources
            drawFont.Dispose();
            brush.Dispose();
            drawFormat.Dispose();
        }