public int ComboBoxAddItem(ImageComboBoxItem item) { item.Text = (item.Text.Length == 0)?item.GetType().Name + base.Items.Count.ToString():item.Text; base.Items.Add(item); return(base.Items.Count - 1); }
/// <summary> /// Helper method for drawing items . /// </summary> /// <param name="e"></param> private void DrawItemHelperForItems(DrawItemEventArgs e) { e.DrawFocusRectangle(); e.DrawBackground(); ImageComboBoxItem item = (ImageComboBoxItem)this.Items [e.Index]; if (item.Font == null) { item.Font = this.Font; } StringFormat format = new StringFormat(); //format.FormatFlags = StringFormatFlags.NoWrap; format.FormatFlags = StringFormatFlags.NoClip; format.LineAlignment = StringAlignment.Center; int indent = (item.IndentLevel * this.Indent); if (item.ImageIndex != -1) { Image theIcon = this.ImageList.Images [item.ImageIndex]; Bitmap ImageToDraw = new Bitmap(theIcon, e.Bounds.Height - 1, e.Bounds.Height - 1); int IconHeight = ImageToDraw.Height; int IconWidth = ImageToDraw.Width; int offset = 1; if (this.RightToLeft == RightToLeft.Yes) { ImageToDraw.RotateFlip(RotateFlipType.RotateNoneFlipX); format.Alignment = StringAlignment.Far; RectangleF itemRect = new RectangleF((float)(e.Bounds.X - offset), (float)(e.Bounds.Y), (float)(e.Bounds.Width - IconWidth - indent - offset), (float)(e.Bounds.Height)); e.Graphics.DrawString(item.Text, item.Font, new SolidBrush(e.ForeColor), itemRect, format); Rectangle imageRect = new Rectangle(e.Bounds.X + offset + (e.Bounds.Width - (IconWidth + indent)), e.Bounds.Y, IconWidth, IconHeight); e.Graphics.DrawImage(ImageToDraw, imageRect); } else { format.Alignment = StringAlignment.Near; RectangleF itemRect = new RectangleF((float)(e.Bounds.X + IconWidth + indent + offset), (float)(e.Bounds.Y), (float)(e.Bounds.Width - IconWidth - indent - offset), (float)(e.Bounds.Height)); e.Graphics.DrawString(item.Text, item.Font, new SolidBrush(e.ForeColor), itemRect, format); Rectangle imageRect = new Rectangle(e.Bounds.X + offset + indent, e.Bounds.Y, IconWidth, IconHeight); e.Graphics.DrawImage(ImageToDraw, imageRect); } } else { if (this.RightToLeft == RightToLeft.Yes) { format.Alignment = StringAlignment.Far; e.Graphics.DrawString(item.Text, item.Font, new SolidBrush(e.ForeColor), new RectangleF((float)e.Bounds.X, (float)e.Bounds.Y, (float)(e.Bounds.Width - indent), (float)e.Bounds.Height), format); } else { format.Alignment = StringAlignment.Near; e.Graphics.DrawString(item.Text, item.Font, new SolidBrush(e.ForeColor), new RectangleF((float)(e.Bounds.X + indent), (float)e.Bounds.Y, (float)e.Bounds.Width, (float)e.Bounds.Height), format); } } }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(System.ComponentModel.Design.Serialization.InstanceDescriptor)) { Type valueType = value.GetType(); ConstructorInfo ci = valueType.GetConstructor(System.Type.EmptyTypes); ImageComboBoxItem item = (ImageComboBoxItem)value; return(new InstanceDescriptor(ci, null, false)); } else { return(base.ConvertTo(context, culture, value, destinationType)); } }
public void ComboBoxRemoveItem(ImageComboBoxItem item) { base.Items.Remove(item); }
public int ComboBoxInsertItem(int index, ImageComboBoxItem item) { item.Text = (item.Text.Length == 0)?item.GetType().Name + index.ToString():item.Text; base.Items.Insert(index, item); return(index); }
public bool ComboBoxContains(ImageComboBoxItem item) { return(base.Items.Contains(item)); }
void IList.Insert(int index, object item) { ImageComboBoxItem comboItem = (ImageComboBoxItem)item; this.Insert(index, comboItem); }
int IList.Add(object item) { ImageComboBoxItem comboItem = (ImageComboBoxItem)item; return(this.Add(comboItem)); }
public int Add(ImageComboBoxItem item) { return(owner.ComboBoxInsertItem(this.Count, item)); }
public void Insert(int index, ImageComboBoxItem item) { owner.ComboBoxInsertItem(index, item); }
public void Remove(ImageComboBoxItem item) { throw new NotSupportedException(); }