예제 #1
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index == -1 || e.Index > this.Items.Count - 1)
            {
                return;
            }

            e.DrawBackground();

            Rectangle  imageRect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height);
            RectangleF textRectF = RectangleF.FromLTRB(imageRect.Right + 2, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom);

            if (Items[e.Index] is ComboItemImage)
            {
                ComboItemImage Item = (ComboItemImage)Items[e.Index];

                if (Item.Image != null)
                {
                    e.Graphics.DrawImage(Item.Image, imageRect);
                }
            }

            SolidBrush TextBrush = new SolidBrush(this.ForeColor);

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                TextBrush.Color = SystemColors.HighlightText;
            }

            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);

            sf.LineAlignment = StringAlignment.Center;
            sf.Trimming      = StringTrimming.EllipsisCharacter;

            e.Graphics.DrawString(Items[e.Index].ToString(), this.Font, TextBrush, textRectF, sf);
            TextBrush.Dispose();

            base.OnDrawItem(e);
        }
예제 #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
                if (this.Items != null)
                {
                    foreach (Object o in this.Items)
                    {
                        if (o is ComboItemImage)
                        {
                            ComboItemImage item = o as ComboItemImage;

                            item.Image = null;
                        }
                    }
                }
            }
            base.Dispose(disposing);
        }