Esempio n. 1
0
        public CalendarItem(DateTime startTime, DateTime endTime, string description, bool isTentative, string key, string color)
        {
            m_startTime   = startTime;
            m_endTime     = endTime;
            m_description = description;
            m_isTentative = isTentative;
            m_key         = key;

            m_color = ColourTable.CheckColorFromNameRGB(color);
        }
Esempio n. 2
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                m_rowIndex = rowIndex;


                if (IsWorkingTime)
                {
                    graphics.FillRectangle(new SolidBrush(Calendar.ct.WorkingColor), cellBounds);
                }
                else
                {
                    graphics.FillRectangle(new SolidBrush(Calendar.ct.NonWorkingColor), cellBounds);
                }

                if (this.Selected)
                {
                    graphics.FillRectangle(new SolidBrush(Calendar.ct.SelectedBackColor), cellBounds);
                }

                int leftMargin  = 4;
                int rightMargin = 3;

                // Draw the left margin vertical line and fill
                Pen pen = new Pen(new SolidBrush(Calendar.ct.BorderColor));
                graphics.DrawLine(pen, cellBounds.Left + leftMargin, cellBounds.Top, cellBounds.Left + leftMargin, cellBounds.Bottom);
                graphics.FillRectangle(new SolidBrush(Calendar.ct.LeftMarginFillColor), cellBounds.Left, cellBounds.Top, leftMargin, cellBounds.Height);

                // Draw the bottom end of cell
                if (this.EndTime.Minute == 0)
                {
                    graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.HourEndingColor)), cellBounds.Left + leftMargin + 1, cellBounds.Bottom - 1, cellBounds.Right, cellBounds.Bottom - 1);
                }
                else
                {
                    graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.HalfHourEndingColor)), cellBounds.Left + leftMargin + 1, cellBounds.Bottom - 1, cellBounds.Right, cellBounds.Bottom - 1);
                }

                // Draw the right end of the cell
                graphics.DrawLine(pen, cellBounds.Right - 1, cellBounds.Top, cellBounds.Right - 1, cellBounds.Bottom);

                List <CalendarItem> items = this.CalendarItems;
                if (items == null || items.Count <= 0)
                {
                    return;
                }

                for (int i = 0; i < items.Count; i++)
                {
                    int order = 0;
                    int numberOfItemsOverlapping = this.CountOfItemsOverlappingWithThisItem(items[i], ref order);

                    int widthForMargins = (leftMargin + rightMargin) * (numberOfItemsOverlapping + 1);
                    int widthForItem    = (int)((cellBounds.Width - widthForMargins) / (numberOfItemsOverlapping + 1));

                    int startX = ((leftMargin + widthForItem + rightMargin) * order) + cellBounds.X;

                    // Draw the end of cell for item's portion of the cell
                    if (this.EndTime.Minute == 0)
                    {
                        graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.HourEndingColor)), startX + leftMargin + 1, cellBounds.Bottom - 1, startX + leftMargin + widthForItem + rightMargin, cellBounds.Bottom - 1);
                    }
                    else
                    {
                        graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.HalfHourEndingColor)), startX + leftMargin + 1, cellBounds.Bottom - 1, startX + leftMargin + widthForItem + rightMargin, cellBounds.Bottom - 1);
                    }

                    // Fill the back color (Gradient) for the item
                    Rectangle           ItemRect = new Rectangle(startX + leftMargin, cellBounds.Top, widthForItem, cellBounds.Height);
                    LinearGradientBrush lgb      = new LinearGradientBrush(ItemRect, ColourTable.getLightColor(items[i].Color, 110), items[i].Color, LinearGradientMode.Horizontal);
                    graphics.FillRectangle(lgb, ItemRect);
                    //graphics.FillRectangle(new SolidBrush(items[i].Color), startX + leftMargin, cellBounds.Top, widthForItem, cellBounds.Height);

                    // Fill the left margin
                    if (items[i].IsTentative)
                    {
                        HatchBrush hb = new HatchBrush(HatchStyle.WideUpwardDiagonal, Calendar.ct.LeftMarginFillColor, Calendar.ct.ItemLeftMarginColor);
                        graphics.FillRectangle(hb, startX, cellBounds.Top, leftMargin, cellBounds.Height);
                    }
                    else
                    {
                        graphics.FillRectangle(new SolidBrush(Calendar.ct.ItemLeftMarginColor), startX, cellBounds.Top, leftMargin, cellBounds.Height);
                    }

                    // Draw the top horizontal line and draw description
                    if (items[i].StartTime.Equals(this.StartTime))
                    {
                        graphics.DrawLine(pen, startX, cellBounds.Top, startX + leftMargin + widthForItem, cellBounds.Top);
                        PointF p = new PointF((float)(startX + leftMargin + 2), (float)(cellBounds.Top + 2));
                        graphics.DrawString(items[i].Description, new Font("Arial", 8), Calendar.ct.ForeBrush, p);
                    }

                    // Draw the startX (left most) vertical line
                    graphics.DrawLine(pen, startX, cellBounds.Top, startX, cellBounds.Bottom);

                    // Draw the left margin vertical line
                    graphics.DrawLine(pen, startX + leftMargin, cellBounds.Top, startX + leftMargin, cellBounds.Bottom);

                    // Draw the right vertical line
                    graphics.DrawLine(pen, startX + leftMargin + widthForItem, cellBounds.Top, startX + leftMargin + widthForItem, cellBounds.Bottom);

                    // Draw the bottom horizontal line of the item
                    if (items[i].EndTime.Equals(this.EndTime))
                    {
                        graphics.DrawLine(pen, startX, cellBounds.Bottom - 1, startX + leftMargin + widthForItem, cellBounds.Bottom - 1);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }