Exemplo n.º 1
0
 /// <summary>
 /// 清理鼠标所在项区域的阴影.
 /// </summary>
 private void ClearItemMouseOn()
 {
     if (m_mouseOnItem != null)
     {
         this.Invalidate(new Rectangle(
                             m_mouseOnItem.Bounds.X, m_mouseOnItem.Bounds.Y - chatVScroll.Value,
                             m_mouseOnItem.Bounds.Width, m_mouseOnItem.Bounds.Height));
         m_mouseOnItem = null;
     }
 }
Exemplo n.º 2
0
        protected virtual void DrawItem(Graphics g, TextGroupItem item, Rectangle rectItem, SolidBrush sb)
        {
            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.SetTabStops(0.0F, new float[] { 20.0F });
            if (item.Equals(m_mouseOnItem))           //根据列表项现在的状态绘制相应的背景色
            {
                sb.Color = this.itemMouseOnColor;
            }
            else
            {
                sb.Color = this.itemColor;
            }
            g.FillRectangle(sb, rectItem);


            if (item.IsOpen)
            {
                //如果展开的画绘制 展开的三角形
                sb.Color = this.arrowColor;
                g.FillPolygon(sb, new Point[] {
                    new Point(2, rectItem.Top + 11),
                    new Point(12, rectItem.Top + 11),
                    new Point(7, rectItem.Top + 16)
                });
            }
            else
            {
                //绘制 不展开的三角形.
                sb.Color = this.arrowColor;
                g.FillPolygon(sb, new Point[] {
                    new Point(5, rectItem.Top + 8),
                    new Point(5, rectItem.Top + 18),
                    new Point(10, rectItem.Top + 13)
                });
            }
            // 绘制文本.
            string strItem = "\t" + item.Text;

            sb.Color     = this.ForeColor;
            sf.Alignment = StringAlignment.Near;
            g.DrawString(strItem, this.Font, sb, rectItem, sf);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 鼠标移动 处理
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            m_ptMousePos = e.Location;
            if (chatVScroll.IsMouseDown)
            {          //如果滚动条的滑块处于被点击 那么移动
                chatVScroll.MoveSliderFromLocation(e.Y);
                return;
            }
            if (chatVScroll.ShouldBeDraw)
            {
                //如果控件上有滚动条 判断鼠标是否在滚动条区域移动
                if (chatVScroll.Bounds.Contains(m_ptMousePos))
                {
                    ClearItemMouseOn();
                    ClearSubItemMouseOn();
                    if (chatVScroll.SliderBounds.Contains(m_ptMousePos))
                    {
                        chatVScroll.IsMouseOnSlider = true;
                    }
                    else
                    {
                        chatVScroll.IsMouseOnSlider = false;
                    }
                    if (chatVScroll.UpBounds.Contains(m_ptMousePos))
                    {
                        chatVScroll.IsMouseOnUp = true;
                    }
                    else
                    {
                        chatVScroll.IsMouseOnUp = false;
                    }
                    if (chatVScroll.DownBounds.Contains(m_ptMousePos))
                    {
                        chatVScroll.IsMouseOnDown = true;
                    }
                    else
                    {
                        chatVScroll.IsMouseOnDown = false;
                    }
                    return;
                }
                else
                {
                    chatVScroll.ClearAllMouseOn();
                }
            }

            //如果不在滚动条范围类 那么根据滚动条当前值计算虚拟的一个坐标
            m_ptMousePos.Y += chatVScroll.Value;

            #region 新算法
            foreach (var item in Items)
            {
                if (item.Bounds.Contains(m_ptMousePos))
                {
                    if (item.IsOpen)
                    {
                        //子项是展开的.查找子项.
                        foreach (var subitem in item.SubItems)
                        {
                            //鼠标在子项内.
                            if (subitem.Bounds.Contains(m_ptMousePos))
                            {
                                if (subitem.Equals(m_mouseOnSubItem))//与上次的子项一致.
                                {
                                    return;
                                }
                                else
                                {
                                    //引发鼠标在子项上的事件.
                                    OnMouseOnSubItem(new GroupListBoxEventArgs(item, subitem));
                                }
                                ClearSubItemMouseOn();
                                ClearItemMouseOn();
                                m_mouseOnSubItem = subitem;
                                this.Invalidate(new Rectangle(
                                                    subitem.Bounds.X, subitem.Bounds.Y - chatVScroll.Value,
                                                    subitem.Bounds.Width, subitem.Bounds.Height));
                                return;
                            }
                        }
                        ClearSubItemMouseOn();

                        //子项没有发现 那么判断是否在列表上面
                        if (new Rectangle(0, item.Bounds.Top - chatVScroll.Value, this.Width, 20).Contains(e.Location))
                        {
                            //在原先的项上.
                            if (item.Equals(m_mouseOnItem))
                            {
                                return;
                            }

                            //不再原先的项上
                            ClearItemMouseOn();
                            m_mouseOnItem = item;
                            this.Invalidate(new Rectangle(
                                                m_mouseOnItem.Bounds.X, m_mouseOnItem.Bounds.Y - chatVScroll.Value,
                                                m_mouseOnItem.Bounds.Width, m_mouseOnItem.Bounds.Height));
                            return;
                        }
                    }
                    else
                    {
                        if (item.Equals(m_mouseOnItem))
                        {
                            return;
                        }
                        ClearItemMouseOn();
                        ClearSubItemMouseOn();
                        m_mouseOnItem = item;
                        //绘制指定的区域.
                        this.Invalidate(new Rectangle(
                                            m_mouseOnItem.Bounds.X, m_mouseOnItem.Bounds.Y - chatVScroll.Value,
                                            m_mouseOnItem.Bounds.Width, m_mouseOnItem.Bounds.Height));
                        return;
                    }
                }
            }
            #endregion

            #region  老算法

            //for (int i = 0, Len = Items.Count; i < Len; i++)
            //{
            //    然后判断鼠标是否移动到某一列表项或者子项
            //    if (Items[i].Bounds.Contains(m_ptMousePos))
            //    {
            //        if (Items[i].IsOpen)
            //        {
            //            如果展开 判断鼠标是否在某一子项上面
            //            for (int j = 0, lenSubItem = Items[i].SubItems.Count; j < lenSubItem; j++)
            //            {
            //                if (Items[i].SubItems[j].Bounds.Contains(m_ptMousePos))
            //                {
            //                    if (m_mouseOnSubItem != null)
            //                    {
            //                        如果当前鼠标下子项不为空
            //                        if (Items[i].SubItems[j].HeadRect.Contains(m_ptMousePos))
            //                        {     //判断鼠标是否在头像内
            //                            //if (!m_bOnMouseEnterHeaded)
            //                            //{       //如果没有触发进入事件 那么触发用户绑定的事件
            //                            //   // OnMouseEnterHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
            //                            //    //m_bOnMouseEnterHeaded = true;
            //                            //}
            //                        }
            //                        else
            //                        {
            //                            //if (m_bOnMouseEnterHeaded)
            //                            //{        //如果已经执行过进入事件 那触发用户绑定的离开事件
            //                            //    OnMouseLeaveHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
            //                            //    m_bOnMouseEnterHeaded = false;
            //                            //}
            //                        }
            //                    }
            //                    if (Items[i].SubItems[j].Equals(m_mouseOnSubItem))
            //                    {
            //                        return;
            //                    }
            //                    ClearSubItemMouseOn();
            //                    ClearItemMouseOn();
            //                    m_mouseOnSubItem = Items[i].SubItems[j];
            //                    this.Invalidate(new Rectangle(
            //                        m_mouseOnSubItem.Bounds.X, m_mouseOnSubItem.Bounds.Y - chatVScroll.Value,
            //                        m_mouseOnSubItem.Bounds.Width, m_mouseOnSubItem.Bounds.Height));
            //                    this.Invalidate();
            //                    return;
            //                }
            //            }
            //            ClearSubItemMouseOn();      //循环做完没发现子项 那么判断是否在列表上面
            //            if (new Rectangle(0, Items[i].Bounds.Top - chatVScroll.Value, this.Width, 20).Contains(e.Location))
            //            {
            //                if (Items[i].Equals(m_mouseOnItem))
            //                    return;
            //                ClearItemMouseOn();
            //                m_mouseOnItem = Items[i];
            //                this.Invalidate(new Rectangle(
            //                    m_mouseOnItem.Bounds.X, m_mouseOnItem.Bounds.Y - chatVScroll.Value,
            //                    m_mouseOnItem.Bounds.Width, m_mouseOnItem.Bounds.Height));
            //                this.Invalidate();
            //                return;
            //            }
            //        }
            //        else
            //        {        //如果列表项没有展开 重绘列表项
            //            if (Items[i].Equals(m_mouseOnItem))
            //                return;
            //            ClearItemMouseOn();
            //            ClearSubItemMouseOn();
            //            m_mouseOnItem = Items[i];
            //            this.Invalidate(new Rectangle(
            //                    m_mouseOnItem.Bounds.X, m_mouseOnItem.Bounds.Y - chatVScroll.Value,
            //                    m_mouseOnItem.Bounds.Width, m_mouseOnItem.Bounds.Height));
            //            this.Invalidate();
            //            return;
            //        }
            //    }
            //}
            #endregion


            //若循环结束 既不在列表上也不再子项上 清空上面的颜色
            ClearItemMouseOn();
            ClearSubItemMouseOn();
            base.OnMouseMove(e);
        }
Exemplo n.º 4
0
 public GroupListBoxEventArgs(TextGroupItem mouseOnSubItem, TextSubItem selectSubItem)
 {
     _SelectSubItem  = selectSubItem;
     _MouseOnsubItem = mouseOnSubItem;
 }