示例#1
0
 public bool SelectEntry(string text)
 {
     for (int i = 0; i < Items.Count; i++)
     {
         ListBoxEntryItem item = (ListBoxEntryItem)Items[i];
         if (item.Name == text)
         {
             SelectedIndex = i;
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);
            // get post-source we are rendering
            ListBoxEntryItem item = Items[e.Index] as ListBoxEntryItem;

            // determine image and text to use
            Bitmap postSourceImage = item.Image;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            // center the image within the list box
            int imageLeft = e.Bounds.Left + ((e.Bounds.Width / 2) - (ScaleX(postSourceImage.Width) / 2));
            int imageTop  = e.Bounds.Top + ScaleY(LARGE_TOP_INSET);

            g.DrawImage(false, postSourceImage, new Rectangle(imageLeft, imageTop, ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

            // calculate standard text drawing metrics
            float leftMargin = ScaleX(ELEMENT_PADDING);
            float topMargin  = imageTop + ScaleY(postSourceImage.Height) + ScaleY(ELEMENT_PADDING);
            float fontHeight = e.Font.GetHeight();

            // caption
            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                (int)leftMargin,
                (int)topMargin,
                e.Bounds.Width - (2 * ScaleX(ELEMENT_PADDING)),
                (int)fontHeight * TITLE_LINES);

            // draw caption
            g.DrawText(item.Name, e.Font, layoutRectangle, textColor, TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak);

            // draw focus rectangle if necessary
            e.DrawFocusRectangle();
        }