Beispiel #1
0
        /// <param name="g">绘制图面.</param>
        /// <param name="item">要绘制的GroupCellItem</param>
        /// <param name="rect">绘制的区域.只提供起点(x,y),具体大小可以在重载时自行确定.</param>
        /// <returns>下一个GroupItem的起点区域.</returns>
        protected virtual Rectangle DrawCellItem(Graphics g, GroupCellItem item, Rectangle rect)
        {
            //绘制Item
            rect.Height = _CellItemHeight;
            SolidBrush sb;

            if (item.Equals(_MouseOnCellItem))
            {
                sb = new SolidBrush(MouseOnCellItemColor);
            }
            else
            {
                sb = new SolidBrush(BackColor);
            }
            //FillItem(g, rect, sb);
            g.FillRectangle(sb, rect);

            StringFormat sf = new StringFormat()
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Near,
                FormatFlags   = StringFormatFlags.NoClip,
            };

            sf.SetTabStops(0.0F, new float[] { 20.0F });
            sb.Color = Color.Black;
            g.DrawString(item.Text, Font, sb, rect, sf);

            item.Bounds = rect;
            return(GetNextBounds(rect));
        }
Beispiel #2
0
 /// <summary>
 /// 清理GroupCellItem区域.
 /// </summary>
 private void ClearCellItemBounds()
 {
     if (_MouseOnCellItem != null)
     {
         Rectangle rect = _MouseOnCellItem.Bounds;
         rect.Y -= VerticalScroll.Value;
         rect.X  = 0;
         this.Invalidate(rect);
         _MouseOnCellItem = null;
     }
 }
Beispiel #3
0
        /// <summary>
        /// 鼠标点击处理.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseClick(MouseEventArgs e)
        {
            Debug.WriteLine("VS {0} Height {2} sum{3} Mouse {1} ".FormatWith(VerticalScroll.Value, e.Y, this.Height, VerticalScroll.Value + this.Height));
            Point Pos = e.Location;

            int index = this.VerticalScroll.Value;

            Pos.X += this.HorizontalScroll.Value;
            Pos.Y += this.VerticalScroll.Value;


            if (e.Button == System.Windows.Forms.MouseButtons.Left || e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                Debug.WriteLine("鼠标点击位置:{0}".FormatWith(Pos));
                foreach (var item in Items)
                {
                    if (item.Bounds.Contains(Pos))
                    {
                        _MouseSelectCellItem = null;
                        item.IsOpen          = !item.IsOpen;
                        OnItemClick(new DataEventArgs <GroupItem>(item));
                        //this.Invalidate();
                        Debug.WriteLine("Item 位置{0}".FormatWith(item.Bounds));
                        return;
                    }
                    else
                    {
                        if (item.IsOpen)
                        {
                            foreach (var sitem in item.SubItems)
                            {
                                if (sitem.Bounds.Contains(Pos))
                                {
                                    _MouseSelectCellItem = null;
                                    sitem.IsOpen         = !sitem.IsOpen;
                                    //this.Invalidate();
                                    OnSubItemClick(new DataEventArgs <GroupSubItem>(sitem));
                                    Debug.WriteLine("{2} {1} 位置{0}".FormatWith(sitem.Bounds, sitem.Text, sitem.Father.Text));
                                    return;
                                }
                                else
                                {
                                    if (sitem.IsOpen)
                                    {
                                        foreach (var citem in sitem.SubItems)
                                        {
                                            if (!citem.Equals(_MouseSelectCellItem) && citem.Bounds.Contains(Pos))
                                            {
                                                _MouseSelectCellItem = citem;
                                                this.Invalidate();
                                                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                                                {
                                                    OnCellItemClick(new DataEventArgs <GroupCellItem>(citem));
                                                }
                                                else
                                                {
                                                    OnCellItemDoubleClick(new DataEventArgs <GroupCellItem>(citem));
                                                }
                                                Debug.WriteLine("{1} -{2} -{3}- Cell 位置{0}".FormatWith(citem.Bounds, item.Text, sitem.Text, citem.Text));
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //Debug.WriteLine("没有找到任何项");
                //foreach (var item in Items)
                //{
                //    Debug.WriteLine(item.Bounds);
                //}
            }
            base.OnMouseClick(e);
        }
Beispiel #4
0
        /// <summary>
        /// 鼠标移动处理.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            _MounsePos = e.Location;
            int index = this.VerticalScroll.Value;

            _MounsePos.X += this.HorizontalScroll.Value;
            _MounsePos.Y += this.VerticalScroll.Value;

            Rectangle rect;

            foreach (var item in _Items)
            {
                if (item.Bounds.Contains(_MounsePos))
                {
                    if (item.Equals(_MouseOnItem))//子项与上一次是相等的.
                    {
                        Debug.WriteLine("Item 与上次一样 ");
                        return;
                    }
                    else
                    {
                        ClearBounds();
                        _MouseOnItem = item;
                        rect         = item.Bounds;
                        rect.Y      -= index;
                        this.Invalidate(rect);
                        Debug.WriteLine("被选中的是Item {0}".FormatWith(item.Bounds));
                        return;
                    }
                }
                else
                {
                    if (item.IsOpen)
                    {
                        foreach (var sitem in item.SubItems)
                        {
                            if (sitem.Bounds.Contains(_MounsePos))
                            {
                                if (sitem.Equals(_MouseOnSubItem))
                                {
                                    Debug.WriteLine("SubItem 与上次一样 ");
                                    return;
                                }
                                else
                                {
                                    ClearBounds();
                                    _MouseOnSubItem = sitem;
                                    rect            = sitem.Bounds;
                                    rect.Y         -= index;
                                    this.Invalidate(rect);
                                    Debug.WriteLine("被选中的是SubItem {0}".FormatWith(sitem.Bounds));
                                    return;
                                }
                            }
                            else
                            {
                                if (sitem.IsOpen)
                                {
                                    foreach (var citem in sitem.SubItems)
                                    {
                                        if (citem.Bounds.Contains(_MounsePos))
                                        {
                                            ClearBounds();
                                            _MouseOnCellItem = citem;
                                            rect             = citem.Bounds;
                                            rect.Y          -= index;
                                            OnMouseOnCellItem(new DataEventArgs <GroupCellItem>(citem));
                                            this.Invalidate(rect);
                                            Debug.WriteLine("被选中的是CellItem {0}".FormatWith(citem.Bounds));
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ClearBounds();
            Debug.WriteLine("没有找到任何项");
            foreach (var item in Items)
            {
                Debug.WriteLine(item.Bounds);
            }
        }