Exemplo n.º 1
0
            /// <summary>
            /// 移除一个子项
            /// </summary>
            /// <param name="subItem">要移除的子项</param>
            public void Remove(ChatListSubItem subItem)
            {
                int index = this.IndexOf(subItem);

                if (-1 != index)
                {
                    this.RemoveAt(index);
                }
            }
Exemplo n.º 2
0
        //实现排序接口
        int IComparable.CompareTo(object obj)
        {
            if (!(obj is ChatListSubItem))
            {
                throw new NotImplementedException("obj is not ChatListSubItem");
            }
            ChatListSubItem subItem = obj as ChatListSubItem;

            return((this.status).CompareTo(subItem.status));
        }
Exemplo n.º 3
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
                                         object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("DestinationType cannot be null");
            }
            //MessageBox.Show("Convertto OK");
            if (destinationType == typeof(InstanceDescriptor) && (value is ChatListItem))
            {
                ConstructorInfo   constructor = null;
                ChatListItem      item        = (ChatListItem)value;
                ChatListSubItem[] subItems    = null;
                //MessageBox.Show("Convertto Start Item:" + item.Text);
                //MessageBox.Show("Item.SubItems.Count:" + item.SubItems.Count);
                if (item.SubItems.Count > 0)
                {
                    subItems = new ChatListSubItem[item.SubItems.Count];
                    item.SubItems.CopyTo(subItems, 0);
                }
                //MessageBox.Show("Item.SubItems.Count:" + item.SubItems.Count);
                if (item.Text != null && subItems != null)
                {
                    constructor = typeof(ChatListItem).GetConstructor(new Type[] { typeof(string), typeof(ChatListSubItem[]) });
                }
                //MessageBox.Show("Constructor(Text,item[]):" + (constructor != null));
                if (constructor != null)
                {
                    return(new InstanceDescriptor(constructor, new object[] { item.Text, subItems }, false));
                }

                if (subItems != null)
                {
                    constructor = typeof(ChatListItem).GetConstructor(new Type[] { typeof(ChatListSubItem[]) });
                }
                if (constructor != null)
                {
                    return(new InstanceDescriptor(constructor, new object[] { subItems }, false));
                }
                if (item.Text != null)
                {
                    //MessageBox.Show("StartGetConstructor(text)");
                    constructor = typeof(ChatListItem).GetConstructor(new Type[] { typeof(string), typeof(bool) });
                }
                //MessageBox.Show("Constructor(Text):" + (constructor != null));
                if (constructor != null)
                {
                    //System.Windows.Forms.MessageBox.Show("text OK");
                    return(new InstanceDescriptor(constructor, new object[] { item.Text, item.IsOpen }));
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Exemplo n.º 4
0
 //确认存储空间
 private void EnsureSpace(int elements)
 {
     if (m_arrSubItems == null)
     {
         m_arrSubItems = new ChatListSubItem[Math.Max(elements, 4)];
     }
     else if (elements + this.count > m_arrSubItems.Length)
     {
         ChatListSubItem[] arrTemp = new ChatListSubItem[Math.Max(m_arrSubItems.Length * 2, elements + this.count)];
         m_arrSubItems.CopyTo(arrTemp, 0);
         m_arrSubItems = arrTemp;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 根据在线状态添加一个子项
 /// </summary>
 /// <param name="subItem">要添加的子项</param>
 public void AddAccordingToStatus(ChatListSubItem subItem)
 {
     if (subItem.Status == ChatListSubItem.UserStatus.OffLine)
     {
         this.Add(subItem);
         return;
     }
     for (int i = 0, len = this.count; i < len; i++)
     {
         if (subItem.Status <= m_arrSubItems[i].Status)
         {
             this.Insert(i, subItem);
             return;
         }
     }
     this.Add(subItem);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 添加一个子项
 /// </summary>
 /// <param name="subItem">要添加的子项</param>
 public void Add(ChatListSubItem subItem)
 {
     if (subItem == null)
     {
         throw new ArgumentNullException("SubItem cannot be null");
     }
     this.EnsureSpace(1);
     if (-1 == IndexOf(subItem))
     {
         subItem.OwnerListItem       = owner;
         m_arrSubItems[this.count++] = subItem;
         if (this.owner.OwnerChatListBox != null)
         {
             this.owner.OwnerChatListBox.Invalidate();
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// 根据索引插入一个子项
 /// </summary>
 /// <param name="index">索引位置</param>
 /// <param name="subItem">要插入的子项</param>
 public void Insert(int index, ChatListSubItem subItem)
 {
     if (index < 0 || index >= this.count)
     {
         throw new IndexOutOfRangeException("Index was outside the bounds of the array");
     }
     if (subItem == null)
     {
         throw new ArgumentNullException("SubItem cannot be null");
     }
     this.EnsureSpace(1);
     for (int i = this.count; i > index; i--)
     {
         m_arrSubItems[i] = m_arrSubItems[i - 1];
     }
     subItem.OwnerListItem = this.owner;
     m_arrSubItems[index]  = subItem;
     this.count++;
     if (this.owner.OwnerChatListBox != null)
     {
         this.owner.OwnerChatListBox.Invalidate();
     }
 }
Exemplo n.º 8
0
 public ChatListEventArgs(ChatListSubItem mouseonsubitem, ChatListSubItem selectsubitem)
 {
     this.mouseOnSubItem = mouseonsubitem;
     this.selectSubItem  = selectsubitem;
 }
Exemplo n.º 9
0
 /// <summary>
 /// 判断子项是否在集合内
 /// </summary>
 /// <param name="subItem">要判断的子项</param>
 /// <returns>是否在集合内</returns>
 public bool Contains(ChatListSubItem subItem)
 {
     return(this.IndexOf(subItem) != -1);
 }
Exemplo n.º 10
0
 /// <summary>
 /// 获取索引位置
 /// </summary>
 /// <param name="subItem">要获取索引的子项</param>
 /// <returns>索引</returns>
 public int IndexOf(ChatListSubItem subItem)
 {
     return(Array.IndexOf <ChatListSubItem>(m_arrSubItems, subItem));
 }