示例#1
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            ImageListBoxItem item = e.Index < 0 || this.DesignMode ? null : Items[e.Index] as ImageListBoxItem;
            bool             draw = m_ImageList != null && (item != null);

            if (draw)
            {
                e.DrawBackground();
                e.DrawFocusRectangle();

                Size imageSize = m_ImageList.ImageSize;
                if (this.ItemHeight != imageSize.Height + 2)
                {
                    this.ItemHeight = imageSize.Height + 2;
                }

                CheckHorizonalScroll(e.Graphics, e.Font);

                Rectangle bounds        = e.Bounds;
                string    strTextToDraw = item.ToString();
                Color     color         = e.ForeColor;

                if (item.ImageIndex > -1 && item.ImageIndex < m_ImageList.Images.Count)
                {
                    m_ImageList.Draw(e.Graphics, bounds.Left, bounds.Top, item.ImageIndex);
                    if (item.Color != Color.Empty)
                    {
                        color = item.Color;
                    }
                }

                e.Graphics.DrawString(strTextToDraw, e.Font, new SolidBrush(color), /*bounds.Left*/ 0 + imageSize.Width, bounds.Top + (int)((this.ItemHeight - m_MaxStringHeigth) / 2));
            }
            else
            {
                base.OnDrawItem(e);
            }
        }