Ejemplo n.º 1
0
 public int IndexOf(string Text)
 {
     for (int i = 1; i < Items.Count; i++)
     {
         ImageComboItem item = (Items[i] as ImageComboItem);
         if (item.Text == Text)
         {
             return(i);
         }
     }
     return(-1);
 }
Ejemplo n.º 2
0
        protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
        {
            base.OnDrawItem(e);

            e.DrawBackground();
            e.DrawFocusRectangle();

            if (e.Index < 0)
            {
                return;
            }

            if (!(this.Items[e.Index] is ImageComboItem))
            {
                e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top);
                return;
            }

            ImageComboItem CurrItem = this.Items[e.Index] as ImageComboItem;
            SizeF          fontSize = e.Graphics.MeasureString(CurrItem.Text, CurrItem.Font);
            SolidBrush     brush    = new SolidBrush(CurrItem.ForeColor);
            int            imageX   = e.Bounds.Left;

            if (CurrItem.Text != string.Empty && CurrItem.TextAlign == EImageComboItemTextAlign.Left)
            {
                e.Graphics.DrawString(CurrItem.Text, CurrItem.Font, brush, e.Bounds.Left, e.Bounds.Top + (mImageList.ImageSize.Height / 2) - fontSize.Height / 2);
            }

            if (mImageList != null && CurrItem.ImageIndex != -1)
            {
                if (CurrItem.TextAlign == EImageComboItemTextAlign.Left)
                {
                    imageX += (int)fontSize.Width;
                }

                if (mImagePlace > imageX)
                {
                    imageX = mImagePlace;
                }
                ImageList.Draw(e.Graphics, imageX, e.Bounds.Top, CurrItem.ImageIndex);
            }

            if (CurrItem.Text != string.Empty && CurrItem.TextAlign == EImageComboItemTextAlign.Right)
            {
                imageX += ImageList.ImageSize.Width + 10;
                e.Graphics.DrawString(CurrItem.Text, CurrItem.Font, brush, imageX, e.Bounds.Top + (mImageList.ImageSize.Height / 2) - fontSize.Height / 2);
            }
        }