Esempio n. 1
0
        private void TodaysEventsListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            TodaysEventsListBox.SuspendLayout();

            Font     font;
            Brush    brush;
            Brush    selectedBrush = new SolidBrush(Color.White);
            int      status        = -1;
            string   title         = string.Empty;
            Graphics g             = e.Graphics;
            ListBox  lb            = (ListBox)sender;
            int      index         = e.Index;

            if (index > -1)
            {
                SavedEvent @event = null;
                try { @event = (SavedEvent)lb.Items[index]; } catch (Exception) { /*Something happened*/ }

                if (@event != null)
                {
                    DateAndTime currDate       = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime());
                    DateAndTime eventStartDate = @event.ActivationDate;
                    DateAndTime eventEndDate   = @event.DeactivationDate;

                    status = @event.Completed ?
                             4 : TimeAndDateUtility.IsBeforeRange(eventStartDate, currDate) ?
                             1 : TimeAndDateUtility.IsWithinRange(eventStartDate, currDate, eventEndDate) ?
                             2 : 3;

                    title = @event.Title;
                }
            }

            switch (status)
            {
            case 1:
                e.DrawBackground();
                font  = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
                brush = Brushes.DarkSlateGray;
                break;

            case 2:
                e.DrawBackground();
                font  = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Italic);
                brush = Brushes.DarkSlateBlue;
                break;

            case 3:
                e.DrawBackground();
                font  = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
                brush = Brushes.DarkRed;
                break;

            case 4:
                e.DrawBackground();
                font  = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold | FontStyle.Italic);
                brush = Brushes.DarkGreen;
                break;

            default:
                font  = e.Font;
                brush = Brushes.Black;
                break;
            }

            if (index > -1 && lb.SelectedIndex == index)
            {
                g.FillRectangle(Brushes.Blue, e.Bounds);
                g.DrawString(title, font, selectedBrush, e.Bounds, StringFormat.GenericDefault);
            }
            else
            {
                g.FillRectangle(Brushes.White, e.Bounds);
                g.DrawString(title, font, brush, e.Bounds, StringFormat.GenericDefault);
            }

            TodaysEventsListBox.ResumeLayout();
        }