Example #1
0
        private void eventsListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            // Draw the background of the ListBox control for each item.
            e.DrawBackground();

            // This method is evidently called with a bad index when the list box is cleared
            // and repopulated: just exit if so.
            if (e.Index < 0)
            {
                return;
            }

            // Define the default color of the brush as black.
            Brush myBrush = Brushes.Black;

            // Determine the color of the brush to draw each item based on the index of the item to draw.
            Font   requiredFont = e.Font;
            string padding      = "";

            switch (iEventList.GetLevel(e.Index))
            {
            case 0:
                myBrush      = Brushes.Purple;
                requiredFont = new Font(requiredFont, FontStyle.Bold);
                break;

            case 1:
                myBrush = Brushes.Red;
                padding = "  ";
                break;

            case 2:
                myBrush      = Brushes.Orange;
                requiredFont = new Font(requiredFont, FontStyle.Italic);
                padding      = "    ";
                break;
            }

            // Draw the current item text based on the current Font and the custom brush settings.
            string eventText = padding + eventsListBox.Items[e.Index].ToString();

            e.Graphics.DrawString(eventText, requiredFont, myBrush, e.Bounds, StringFormat.GenericDefault);

            // Add a photo icon if the event has a slideshow
            if (iEventList.GetSlideShow(e.Index) != null)
            {
                imageList.Draw(e.Graphics, e.Bounds.Right - 16, e.Bounds.Top, 0);
            }

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }
Example #2
0
        private void listBoxEvents_DrawItem(object sender, DrawItemEventArgs e)
        {
            // Set the DrawMode property to draw fixed sized items.
            // DO WE NEED THIS?
            listBoxEvents.DrawMode = DrawMode.OwnerDrawFixed;

            // Draw the background of the ListBox control for each item.
            e.DrawBackground();

            // Define the default color of the brush as black.
            Brush myBrush = Brushes.Black;

            // Determine the color of the brush to draw each item based on the index of the item to draw.
            Font   requiredFont = e.Font;
            string padding      = "";

            switch (iEventList.GetLevel(e.Index))
            {
            case 0:
                myBrush      = Brushes.Purple;
                requiredFont = new Font(requiredFont, FontStyle.Bold);
                break;

            case 1:
                myBrush = Brushes.Red;
                padding = "  ";
                break;

            case 2:
                myBrush      = Brushes.Orange;
                requiredFont = new Font(requiredFont, FontStyle.Italic);
                padding      = "    ";
                break;
            }

            // Draw the current item text based on the current Font and the custom brush settings.
            string eventText = padding + listBoxEvents.Items[e.Index].ToString();

            e.Graphics.DrawString(eventText, requiredFont, myBrush, e.Bounds, StringFormat.GenericDefault);

            // Add a photo icon if the event has a slideshow
            if (iEventList.GetSlideShow(e.Index) != null)
            {
                imageList.Draw(e.Graphics, e.Bounds.Right - 16, e.Bounds.Top, 0);
            }

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }