示例#1
0
 /// <summary>
 /// 处理鼠标按键按下事件
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseClick(MouseEventArgs e)
 {
     CheckInvalidateState();
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         bool             changed     = false;
         ImageListBoxItem currentItem = GetItem(e.X, e.Y);
         if (this.MultiSelect)
         {
             if (currentItem != null)
             {
                 currentItem.Selected = !currentItem.Selected;
                 this.InvalidateItem(currentItem);
                 changed = true;
             }
         }
         else
         {
             foreach (ImageListBoxItem item in this.Items)
             {
                 if (item.Selected != (item == currentItem))
                 {
                     item.Selected = (item == currentItem);
                     this.InvalidateItem(item);
                     changed = true;
                 }
             }
         }
         if (changed)
         {
             OnSelectedIndexChanged(EventArgs.Empty);
         }
     }
     base.OnMouseClick(e);
 }
示例#2
0
 private void InvalidateItem(ImageListBoxItem item)
 {
     CheckInvalidateState();
     if (item != null)
     {
         this.Invalidate(GetItemBounds(item));
     }
 }
示例#3
0
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object Value)
 {
     if (Value is InstanceDescriptor)
     {
         ImageListBoxItem   item       = new ImageListBoxItem();
         InstanceDescriptor descriptor = (InstanceDescriptor)Value;
         return(item);
     }
     return(base.ConvertFrom(context, culture, Value));
 }
示例#4
0
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object Value, Type destinationType)
 {
     if (destinationType.Equals(typeof(InstanceDescriptor)))
     {
         //MessageBox.Show("aa");
         ImageListBoxItem   item       = (ImageListBoxItem)Value;
         InstanceDescriptor descriptor = new InstanceDescriptor(typeof(ImageListBoxItem).GetConstructor(new Type[] { }), null, false);
         return(descriptor);
     }
     return(base.ConvertTo(context, culture, Value, destinationType));
 }
示例#5
0
        public Rectangle GetItemBounds(ImageListBoxItem item)
        {
            CheckInvalidateState();
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            int index = this.Items.IndexOf(item);

            if (index >= 0)
            {
                return(new Rectangle(
                           1,
                           this.AutoScrollPosition.Y + this.RuntimeItemHeight * index,
                           this.ClientSize.Width - 2,
                           this.RuntimeItemHeight));
            }
            else
            {
                throw new ArgumentOutOfRangeException("item not in list");
            }
        }