Esempio n. 1
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                DayColumn  dc  = this.OwningColumn as DayColumn;
                DateTime   now = DateTime.Now;
                SolidBrush HeaderColorBrush = Calendar.ct.ForeBrush;

                if (now.CompareTo(dc.StartTime) >= 0 && now.CompareTo(dc.EndTime) <= 0)
                {
                    LinearGradientBrush lgb = new LinearGradientBrush(cellBounds, Calendar.ct.HeaderLight, Calendar.ct.HeaderDark, LinearGradientMode.Vertical);
                    graphics.FillRectangle(lgb, cellBounds);
                    HeaderColorBrush = new SolidBrush(Calendar.ct.SelectedForeColor);
                }
                else
                {
                    graphics.FillRectangle(new SolidBrush(Calendar.ct.BackColor), cellBounds);
                }

                graphics.DrawRectangle(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds);
                graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds.Left, cellBounds.Bottom - 1, cellBounds.Right, cellBounds.Bottom - 1);

                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;

                RectangleF rect = new RectangleF(cellBounds.Left, cellBounds.Top, cellBounds.Width, cellBounds.Height);
                graphics.DrawString(this.Value.ToString(), Calendar.ct.FontStd, HeaderColorBrush, rect, sf);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
Esempio n. 2
0
        public void InitializeDisplay()
        {
            try
            {
                if (this.ColumnCount > 0)
                {
                    this.Columns.Clear();
                }

                //setHeader
                this.EnableHeadersVisualStyles = false;

                this.ColumnHeadersDefaultCellStyle.BackColor = ct.BackColor;
                this.ColumnHeadersDefaultCellStyle.ForeColor = ct.HeaderText;
                this.ColumnHeadersDefaultCellStyle.Font      = ct.FontStd;
                this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
                this.GridColor = ct.SeparatorDark;
                this.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;
                this.BackgroundColor = ct.BackColor;

                switch (DateMode)
                {
                case DateMode.OneDay:
                    this.RowHeadersVisible    = true;
                    this.ColumnHeadersVisible = true;
                    DayColumn dc = new DayColumn(this.StartTime);
                    this.Columns.Add(dc);
                    this.RowCount = 48;
                    for (int i = 0; i < this.RowCount; i++)
                    {
                        this.Rows[i].HeaderCell = new HalfHourRowHeaderCell();
                    }
                    this.RowHeadersWidth                 = 50;
                    this.ColumnHeadersHeight             = 20;
                    this.FirstDisplayedScrollingRowIndex = 16;
                    this.MultiSelect = true;
                    break;

                case DateMode.FiveDay:
                    this.RowHeadersVisible    = true;
                    this.ColumnHeadersVisible = true;
                    for (int i = 0; i < 5; i++)
                    {
                        DayColumn d = new DayColumn(this.StartTime.AddDays(i));
                        this.Columns.Add(d);
                    }
                    this.RowCount = 48;
                    this.FirstDisplayedScrollingRowIndex = 16;
                    for (int i = 0; i < this.RowCount; i++)
                    {
                        this.Rows[i].HeaderCell = new HalfHourRowHeaderCell();
                    }
                    this.RowHeadersWidth     = 50;
                    this.ColumnHeadersHeight = 50;
                    this.MultiSelect         = true;
                    break;

                case DateMode.SevenDay:
                    HalfWeekColumn hc1 = new HalfWeekColumn(this.StartTime);
                    HalfWeekColumn hc2 = new HalfWeekColumn(this.StartTime.AddDays(3));
                    this.Columns.AddRange(hc1, hc2);
                    this.RowCount = 3;
                    DateTime ch = StartTime;
                    for (int i = 0; i < this.RowCount; i++)
                    {
                        CultureInfo ci = CultureInfo.CurrentCulture;
                        int         w  = ci.Calendar.GetWeekOfYear(ch, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
                        this.Rows[i].HeaderCell = new WeekRowHeaderCell(w);
                    }
                    this.RowHeadersVisible    = ShowWeekNumbers;
                    this.ColumnHeadersVisible = false;
                    this.ColumnHeadersHeight  = 50;
                    this.MultiSelect          = true;
                    int height = (int)((this.Height - this.Columns[0].HeaderCell.Size.Height - 2) / 3);
                    for (int i = 0; i < 3; i++)
                    {
                        this.Rows[i].Height = height;
                    }
                    break;

                case DateMode.Month:
                    this.RowHeadersVisible    = ShowWeekNumbers;
                    this.ColumnHeadersVisible = true;
                    this.RowTemplate          = new WeekRow();
                    for (int i = 0; i < 6; i++)
                    {
                        WeekDayColumn c = new WeekDayColumn();
                        c.DisplayIndex = i;
                        this.Columns.Add(c);
                    }
                    this.MultiSelect = true;
                    this.RowCount    = 5;
                    DateTime ch2 = StartTime;
                    for (int i = 0; i < this.RowCount; i++)
                    {
                        CultureInfo ci = CultureInfo.CurrentCulture;
                        int         w  = ci.Calendar.GetWeekOfYear(ch2, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
                        this.Rows[i].HeaderCell = new DayRowHeaderCell(w);
                        ch2 = ch2.AddDays(7);
                    }
                    this.ColumnHeadersHeight = 20;
                    height = (int)((this.Height - this.Columns[0].HeaderCell.Size.Height - 2) / 5);

                    for (int i = 0; i < 5; i++)
                    {
                        this.Rows[i].Height = height;
                    }

                    break;

                default:
                    break;
                }
                this.ClearSelection();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }