Example #1
0
        //计算所有Item的大小
        public void MeasureItems()
        {
            //计算每个项目的高度
            int totleItemHeight = 0;
            int height          = 0;

            using (Graphics g = this.CreateGraphics())
            {
                for (int i = 0; i < this.Items.Count; i++)
                {
                    ScrollableListItem item = this.Items[i];

                    //计算描画矩形区域
                    item.Width = this.ClientSize.Width;

                    OnMeasureItem(new MeasureItemEventArgs(item, g, this.Font));

                    //重新设定Y的位置
                    item.X = 0;
                    item.Y = height + Offset;

                    totleItemHeight += item.Height;

                    height += item.Height;
                }
            }

            this.TotleItemHeight = totleItemHeight;
        }
Example #2
0
        public void Insert(int pos, ScrollableListItem item)
        {
            List <ScrollableListItem> col = new List <ScrollableListItem>();

            col.Add(item);
            InsertRange(pos, col);
        }
Example #3
0
        internal void MeasureItemOnAdd(ScrollableListItem item)
        {
            List <ScrollableListItem> list = new List <ScrollableListItem>(1);

            list.Add(item);

            MeasureItemOnAdd(list);
        }
Example #4
0
 public void Remove(ScrollableListItem item)
 {
     this._list.Remove(item);
     if (this._owner != null)
     {
         this._owner.MeasureItemOnRemove(item);
         this._owner.Invalidate();
     }
 }
Example #5
0
 public void Add(ScrollableListItem item)
 {
     this._list.Add(item);
     if (this._owner != null)
     {
         this._owner.MeasureItemOnAdd(item);
         this._owner.Invalidate();
     }
 }
Example #6
0
 internal void MeasureItemOnRemove(ScrollableListItem item)
 {
     //using (Graphics g = this.CreateGraphics())
     //{
     //删除的项应该不需要再计算了,反正都删除了,是吧?
     //OnMeasureItem(new MeasureItemEventArgs(this.Items.IndexOf(item), item, g, this.Font));
     this.TotleItemHeight -= item.Height;
     //}
 }
Example #7
0
        public void RemoveAt(int index)
        {
            ScrollableListItem item = this._list[index];

            this._list.RemoveAt(index);
            if (this._owner != null)
            {
                this._owner.MeasureItemOnRemove(item);
                this._owner.Invalidate();
            }
        }
Example #8
0
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
            ScrollableListItem item = HitTest(e.Location);

            if (item == null)
            {
                return;
            }

            //设置选择状态
            bool bSelectChange = false;

            if (item.Selected)
            {
                if (this.ToggleSelection)
                {
                    item.Selected = false;
                    this.SelectedItems.Remove(item);
                    bSelectChange = true;
                }
            }
            else
            {
                if (!this.MultipleSelect)
                {
                    //只能单选时
                    foreach (ScrollableListItem i in this.SelectedItems)
                    {
                        i.Selected = false;
                    }
                    this.SelectedItems.Clear();
                }
                item.Selected = true;
                this.SelectedItems.Add(item);
                bSelectChange = true;
            }

            //触发点击事件
            ItemClickedEventArgs args = new ItemClickedEventArgs(item, e.Button, e.Location);

            OnItemClicked(args);

            if (bSelectChange)
            {
                //触发选择变化事件
                OnSelectionChanged(new EventArgs());
            }

            //描绘选择状态
            this.Invalidate(item.Bounds);
        }
Example #9
0
        private void ResetItemsBounds()
        {
            int height = 0;

            for (int i = 0; i < this.Items.Count; i++)
            {
                ScrollableListItem item = this.Items[i];

                item.Y = height + Offset;

                height += item.Height;
            }
        }
Example #10
0
 public DrawItemEventArgs(ScrollableListItem item,
                          Graphics g, bool focus, bool selected,
                          Font font, Color foreColor, Color backColor)
 {
     this.Item              = item;
     this.Graphics          = g;
     this.Font              = font;
     this.ForeColor         = foreColor;
     this.BackColor         = backColor;
     this.SelectedBackColor = LanColor.DarkLight(backColor, -0.06f);
     this.FocusBackColor    = LanColor.DarkLight(backColor, -0.03f);
     this.Focus             = focus;
     this.Selected          = selected;
 }
Example #11
0
        private ScrollableListItem HitTest(Point mousePosition)
        {
            for (int i = 0; i < this.Items.Count; i++)
            {
                ScrollableListItem item = this.Items[i];

                Rectangle rect = item.Bounds;

                if (rect.Contains(mousePosition))
                {
                    return(item);
                }
            }

            return(null);
        }
Example #12
0
        protected virtual void OnDrawItems(Graphics g, Rectangle clipRect)
        {
            for (int i = 0; i < this.Items.Count; i++)
            {
                ScrollableListItem item = this.Items[i];

                Rectangle rect = item.Bounds;

                if (rect.IntersectsWith(clipRect))
                {
                    //不在拖拽滑块,并且鼠标移动到上面就定为Focus
                    bool isFocus = (this.HighlightWithNoFocus || !this.HighlightWithNoFocus && this.Focused) &&
                                   !this._scrollBarHandleDrag && rect.Contains(PointToClient(MousePosition));
                    DrawItemEventArgs args = new DrawItemEventArgs(item, g, isFocus, item.Selected,
                                                                   this.Font, this.ForeColor, this.BackColor);
                    OnDrawItem(args);
                }
            }
        }
Example #13
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            //滚动条区域重绘
            if (this._scrollBarHandleDrag)
            {
                //鼠标按下时拖动,更新滑块偏移
                this.Offset -= (int)(1.0 * (e.Y - this._scrollBarHandleDragMouseOffsetY) * this._totleItemHeight / this.ClientSize.Height);
                this._scrollBarHandleDragMouseOffsetY = e.Y;
            }
            else
            {
                //更新滑块的画刷
                bool focusHandle = this._scrollBarHandleBounds.Contains(e.Location);
                if (focusHandle &&
                    this._scrollBarHandleBrush != SCROLLBAR_HANDLE_BRUSH_FOCUSED)
                {
                    //鼠标移动到上面时候绘制Foused的深色
                    this._scrollBarHandleBrush = SCROLLBAR_HANDLE_BRUSH_FOCUSED;
                }
                else if (!focusHandle &&
                         this._scrollBarHandleBrush != SCROLLBAR_HANDLE_BRUSH_NORMAL)
                {
                    this._scrollBarHandleBrush = SCROLLBAR_HANDLE_BRUSH_NORMAL;
                }
            }

            ScrollableListItem item = HitTest(e.Location);

            if (item != null)
            {
                //触发Hover事件
                ItemHoverEventArgs args = new ItemHoverEventArgs(item, e.Location);
                OnItemHover(args);
            }

            this.Invalidate();
        }
Example #14
0
 public MeasureItemEventArgs(ScrollableListItem item, Graphics g, Font font)
 {
     this.Item     = item;
     this.Graphics = g;
     this.Font     = font;
 }
Example #15
0
 public ItemHoverEventArgs(ScrollableListItem item, Point loc)
 {
     this.Item     = item;
     this.Location = loc;
 }
Example #16
0
 public ItemClickedEventArgs(ScrollableListItem item, MouseButtons button, Point loc)
 {
     this.Item     = item;
     this.Button   = button;
     this.Location = loc;
 }
Example #17
0
 public int IndexOf(ScrollableListItem item)
 {
     return(this._list.IndexOf(item));
 }