Beispiel #1
0
        private void MenuMain_Load(object sender, EventArgs e)
        {
            Rectangle rect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            //Width = rect.Width;
            Height = rect.Height - 50;
            this.Location = new Point(10, 40);

            TitleItem temp_item = new TitleItem();
            temp_item.MainTitle = "订单管理";
            temp_item.SubItem.Add("订单");
            temp_item.SubItem.Add("打样");
            temp_item.SubItem.Add("生产");
            temp_item.SubItem.Add("出货记录");
            temp_item.SubItem.Add("快递记录");
            title.Add(temp_item);

            temp_item = new TitleItem();
            temp_item.MainTitle = "任务管理";
            temp_item.SubItem.Add("进度跟踪");
            temp_item.SubItem.Add("工作日历");
            title.Add(temp_item);

            temp_item = new TitleItem();
            temp_item.MainTitle = "物料管理";
            temp_item.SubItem.Add("面料");
            temp_item.SubItem.Add("辅料");
            temp_item.SubItem.Add("特殊工艺");
            title.Add(temp_item);

            temp_item = new TitleItem();
            temp_item.MainTitle = "关系管理";
            temp_item.SubItem.Add("客户");
            temp_item.SubItem.Add("服装厂");
            temp_item.SubItem.Add("其他厂商");
            temp_item.SubItem.Add("联系人");
            title.Add(temp_item);

            temp_item = new TitleItem();
            temp_item.MainTitle = "文件库";
            temp_item.SubItem.Add("文件库");
            title.Add(temp_item);

            button1.Text = "闪动";
            button2.Text = "插入[离开]";
            button3.Text = "大/小图标";

            chatListBox1.Items.Clear();
            Random rnd = new Random();
            for (int i = 0; i < title.Count; i++)
            {
                ChatListItem item = new ChatListItem(title[i].MainTitle);
                for (int j = 0; j < title[i].SubItem.Count; j++)
                {
                    ChatListSubItem subItem = new ChatListSubItem("", title[i].SubItem[j], "");//注释说明
                    subItem.HeadImage = getHeadImage(title[i].SubItem[j]);
                    subItem.Status = (ChatListSubItem.UserStatus)(j % 6);
                    item.SubItems.AddAccordingToStatus(subItem);
                }
                item.SubItems.Sort();
                chatListBox1.Items.Add(item);
            }
            ChatListItem itema = new ChatListItem("TEST");
            for (int i = 0; i < 5; i++)
            {
                chatListBox1.Items.Add(itema);
            }
            chatListBox1.Items.Remove(itema);
        }
Beispiel #2
0
 /// <summary>
 /// 添加一个列表项的数组
 /// </summary>
 /// <param name="items">要添加的列表项的数组</param>
 public void AddRange(ChatListItem[] items)
 {
     if (items == null)
         throw new ArgumentNullException("Items cannot be null");
     this.EnsureSpace(items.Length);
     try {
         foreach (ChatListItem item in items) {
             if (item == null)
                 throw new ArgumentNullException("Item cannot be null");
             if (-1 == this.IndexOf(item)) {     //重复数据不添加
                 item.OwnerChatListBox = this.owner;
                 m_arrItem[this.count++] = item;
             }
         }
     } finally {
         this.owner.Invalidate();
     }
 }
Beispiel #3
0
 /// <summary>
 /// 判断一个列表项是否在集合内
 /// </summary>
 /// <param name="item">要判断的列表项</param>
 /// <returns>是否在列表项</returns>
 public bool Contains(ChatListItem item)
 {
     return this.IndexOf(item) != -1;
 }
Beispiel #4
0
 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;
     }
 }
Beispiel #5
0
 /// <summary>
 /// 添加一个列表项
 /// </summary>
 /// <param name="item">要添加的列表项</param>
 public void Add(ChatListItem item)
 {
     if (item == null)       //空引用不添加
         throw new ArgumentNullException("Item cannot be null");
     this.EnsureSpace(1);
     if (-1 == this.IndexOf(item)) {         //进制添加重复对象
         item.OwnerChatListBox = this.owner;
         m_arrItem[this.count++] = item;
         this.owner.Invalidate();            //添加进去是 进行重绘
     }
 }
Beispiel #6
0
 /// <summary>
 /// 绘制列表项
 /// </summary>
 /// <param name="g">绘图表面</param>
 /// <param name="item">要绘制的列表项</param>
 /// <param name="rectItem">该列表项的区域</param>
 /// <param name="sb">画刷</param>
 protected virtual void DrawItem(Graphics g, ChatListItem 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 {                                    //如果没有展开判断该列表项下面的子项闪动的个数
         if (item.TwinkleSubItemNumber > 0) {    //如果列表项下面有子项闪动 那么判断闪动状态 是否绘制或者不绘制
             if (item.IsTwinkleHide)             //该布尔值 在线程中不停 取反赋值
                 return;
         }
         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);
     sf.Alignment = StringAlignment.Far;
     //g.DrawString("[" + item.SubItems.GetOnLineNumber() + "/" + item.SubItems.Count + "]", this.Font, sb,
     //    new Rectangle(rectItem.X, rectItem.Y, rectItem.Width - 15, rectItem.Height), sf);
 }
Beispiel #7
0
 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;        //如果不在滚动条范围类 那么根据滚动条当前值计算虚拟的一个坐标
     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;
             }
         }
     }//若循环结束 既不在列表上也不再子项上 清空上面的颜色
     ClearItemMouseOn();
     ClearSubItemMouseOn();
     base.OnMouseMove(e);
 }
Beispiel #8
0
 //确认存储空间
 private void EnsureSpace(int elements)
 {
     if (m_arrItem == null)
         m_arrItem = new ChatListItem[Math.Max(elements, 4)];
     else if (this.count + elements > m_arrItem.Length) {
         ChatListItem[] arrTemp = new ChatListItem[Math.Max(this.count + elements, m_arrItem.Length * 2)];
         m_arrItem.CopyTo(arrTemp, 0);
         m_arrItem = arrTemp;
     }
 }
Beispiel #9
0
 /// <summary>
 /// 移除一个列表项
 /// </summary>
 /// <param name="item">要移除的列表项</param>
 public void Remove(ChatListItem item)
 {
     int index = this.IndexOf(item);
     if (-1 != index)        //如果存在元素 那么根据索引移除
         this.RemoveAt(index);
 }
Beispiel #10
0
 /// <summary>
 /// 根据索引位置插入一个列表项
 /// </summary>
 /// <param name="index">索引位置</param>
 /// <param name="item">要插入的列表项</param>
 public void Insert(int index, ChatListItem item)
 {
     if (index < 0 || index >= this.count)
         throw new IndexOutOfRangeException("Index was outside the bounds of the array");
     if (item == null)
         throw new ArgumentNullException("Item cannot be null");
     this.EnsureSpace(1);
     for (int i = this.count; i > index; i--)
         m_arrItem[i] = m_arrItem[i - 1];
     item.OwnerChatListBox = this.owner;
     m_arrItem[index] = item;
     this.count++;
     this.owner.Invalidate();
 }
Beispiel #11
0
 /// <summary>
 /// 获取列表项所在的索引位置
 /// </summary>
 /// <param name="item">要获取的列表项</param>
 /// <returns>索引位置</returns>
 public int IndexOf(ChatListItem item)
 {
     return Array.IndexOf<ChatListItem>(m_arrItem, item);
 }
Beispiel #12
0
 public ChatListSubItemCollection(ChatListItem owner)
 {
     this.owner = owner;
 }