예제 #1
0
        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);
        }
예제 #2
0
        /// <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);
                }
            }
        }
예제 #3
0
 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));
     }
 }
예제 #4
0
 public void ComboBoxRemoveItem(ImageComboBoxItem item)
 {
     base.Items.Remove(item);
 }
예제 #5
0
 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);
 }
예제 #6
0
 public bool ComboBoxContains(ImageComboBoxItem item)
 {
     return(base.Items.Contains(item));
 }
예제 #7
0
        void IList.Insert(int index, object item)
        {
            ImageComboBoxItem comboItem = (ImageComboBoxItem)item;

            this.Insert(index, comboItem);
        }
예제 #8
0
        int IList.Add(object item)
        {
            ImageComboBoxItem comboItem = (ImageComboBoxItem)item;

            return(this.Add(comboItem));
        }
예제 #9
0
 public int Add(ImageComboBoxItem item)
 {
     return(owner.ComboBoxInsertItem(this.Count, item));
 }
예제 #10
0
 public void Insert(int index, ImageComboBoxItem item)
 {
     owner.ComboBoxInsertItem(index, item);
 }
예제 #11
0
 public void Remove(ImageComboBoxItem item)
 {
     throw new NotSupportedException();
 }