public void Insert(int index, ImageComboBoxItem item) { if (item == null) { throw new ArgumentNullException("item"); } item.Host(Owner); Owner.OldItems.Insert(index, item); }
public int Add(ImageComboBoxItem item) { if (item == null) { throw new ArgumentNullException("item"); } item.Host(Owner); return(Owner.OldItems.Add(item)); }
public ImageComboBoxItemImageIndexer(ImageComboBoxItem owner) { _owner = owner; }
public void Remove(ImageComboBoxItem item) { Owner.OldItems.Remove(item); }
public int IndexOf(ImageComboBoxItem item) { return(Owner.OldItems.IndexOf(item)); }
public bool Contains(ImageComboBoxItem item) { return(Owner.OldItems.Contains(item)); }
private void RePaint() { ImageComboBoxItem item = _Owner.SelectedItem; var rcClient = new NativeMethods.RECT(); NativeMethods.GetClientRect(Handle, ref rcClient); bool rightToLeft = IsRightToLeft(Handle); IntPtr handle = Handle; IntPtr hdc = NativeMethods.GetDC(handle); if (hdc == IntPtr.Zero) { return; } try { using (Graphics g = Graphics.FromHdc(hdc)) { int itemSize = _Owner.ItemHeight; var imageRect = new Rectangle(0, rcClient.Top + (rcClient.Bottom - itemSize) / 2, itemSize, itemSize); var textRect = new Rectangle(0, 0, rcClient.Right - itemSize - 6, rcClient.Bottom); if (rightToLeft) { imageRect.X = rcClient.Right - itemSize - 2; textRect.X = 2; } else { imageRect.X = 2; textRect.X = imageRect.Right + 2; } if (_Owner.Text.Length == 0) { DrawImage(g, imageRect, _Owner.DefaultImage, _Owner.DefaultImageList, 0, _Owner.Focused); if (_Owner.Text.Length == 0 && !string.IsNullOrEmpty(_Owner.EmptyTextTip) && !_Owner.Focused) { TextFormatFlags format = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter; if (_Owner.RightToLeft == RightToLeft.Yes) { format |= (TextFormatFlags.RightToLeft | TextFormatFlags.Right); } TextRenderer.DrawText(g, _Owner.EmptyTextTip, _Owner.Font, textRect, _Owner.EmptyTextTipColor, format); } return; } if (_Owner.Text.Length > 0) { using (var brush = new SolidBrush(_Owner.BackColor)) { g.FillRectangle(brush, imageRect); } } if (_Owner.Items.Count == 0) { DrawImage(g, imageRect, _Owner.DefaultImage, _Owner.DefaultImageList, 0, _Owner.Focused); return; } if (item == null) { return; } DrawImage(g, imageRect, item.Image, _Owner.ImageList, item.ImageIndexer.ActualIndex, _Owner.Focused); } } finally { NativeMethods.ReleaseDC(handle, hdc); } }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index != -1) { ImageComboBoxItem item = Items[e.Index]; Graphics g = e.Graphics; Rectangle bounds = e.Bounds; int indentOffset = Indent * item.Level; if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit) { indentOffset = 0; } int imageWidth = bounds.Height; TextFormatFlags format = TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.WordBreak; Rectangle imageRect = new Rectangle(bounds.Left + indentOffset + 2, bounds.Top, imageWidth, imageWidth); Rectangle textRect = new Rectangle(imageRect.Right + 3, bounds.Y, bounds.Width - imageRect.Width - indentOffset - 5, bounds.Height); var backRect = new Rectangle(textRect.X, textRect.Y + 1, textRect.Width, textRect.Height - 2); backRect.Width = TextRenderer.MeasureText(item.Text, e.Font, textRect.Size, format).Width; if (base.RightToLeft == RightToLeft.Yes) { imageRect.X = bounds.Right - imageRect.Right; textRect.X = bounds.Right - textRect.Right; backRect.X = textRect.Right - backRect.Width; } bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected); Color backColor = selected ? SystemColors.Highlight : base.BackColor; using (Brush backBrush = new SolidBrush(backColor)) { g.FillRectangle(backBrush, backRect); } if (selected) { ControlPaint.DrawFocusRectangle(g, backRect); } Image image = item.Image; if (image != null) { using (var graphics = new InterpolationModeGraphics(g, InterpolationMode.HighQualityBicubic)) { if (selected) { IntPtr hIcon = NativeMethods.ImageList_GetIcon(ImageList.Handle, item.ImageIndexer.ActualIndex, (int)NativeMethods.ImageListDrawFlags.ILD_SELECTED); g.DrawIcon(Icon.FromHandle(hIcon), imageRect); NativeMethods.DestroyIcon(hIcon); } else { g.DrawImage(image, imageRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); } } } TextRenderer.DrawText(g, item.Text, e.Font, textRect, base.ForeColor, format); } }