/// <summary> /// 自定义ListView /// </summary> /// <param name="container"></param> public ListImage(System.ComponentModel.IContainer container) { container.Add(this); _largeImageList = null; _smallImageList = null; _captionImageList = null; _captionImageIndex = -1; _items = new ListImagetemCollection(); _selectedItem = null; _selectedIndex = -1; _items.InsertComplete += new TrasenClasses.GeneralControls.ListImagetemCollection.ItemChangedEventHandler(Items_InsertComplete); _items.RemoveComplete += new TrasenClasses.GeneralControls.ListImagetemCollection.ItemChangedEventHandler(Items_RemoveComplete); _items.ClearComplete += new EventHandler(Items_ClearComplete); this.AutoScroll = true; this.BackColor = SystemColors.Window; _selectedBackColor = SystemColors.Window; _selectedForeColor = SystemColors.WindowText; _view = ViewMode.LargeIcon; _captionText = ""; _captionBackColor = SystemColors.Control; _captionForeColor = SystemColors.WindowText; _captionFont = this.Font; _captionVisible = false; InitializeComponent(); }
/// <summary> /// 向集合中插入指定项 /// </summary> /// <param name="index"></param> /// <param name="item"></param> public void Insert(int index, ListImageItem item) { InnerList.Insert(index, item); if (InsertComplete != null) { ItemChangedEventArgs e = new ItemChangedEventArgs(index, item); InsertComplete(this, e); } }
/// <summary> /// 从集合中移除指定项 /// </summary> /// <param name="item">指定ListImageItem</param> public void Remove(ListImageItem item) { if (RemoveComplete != null) { ItemChangedEventArgs e = new ItemChangedEventArgs(IndexOf(item), item); RemoveComplete(this, e); } InnerList.Remove(item); }
/// <summary> /// 添加一TrasenClasses.GeneralControls.ListImageItem到集合中 /// </summary> /// <param name="item"></param> /// <returns></returns> public int Add(ListImageItem item) { if (Contains(item)) { return(-1); } int index = InnerList.Add(item); if (InsertComplete != null) { ItemChangedEventArgs e = new ItemChangedEventArgs(index, item); InsertComplete(this, e); } return(index); }
/// <summary> /// 设定选中后的样式 /// </summary> /// <param name="selectIndex">要选取项目的索引</param> private void SetSelectItem(int selectIndex) { for (int i = 0; i < _items.Count; i++) { if (i == selectIndex) { _items[i].BackColor = _selectedBackColor; _items[i].ForeColor = _selectedForeColor; _items[i].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; _items[i].Selected = true; _selectedItem = _items[i]; } else { _items[i].BackColor = this.BackColor; _items[i].BorderStyle = System.Windows.Forms.BorderStyle.None; _items[i].Selected = false; } } }
/// <summary> /// 获取指定ListImageItem在集合中的索引 /// </summary> /// <param name="item">指定ListImageItem</param> /// <returns></returns> public int IndexOf(ListImageItem item) { return(InnerList.IndexOf(item)); }
/// <summary> /// 判断集合中是否包含指定ListImageItem /// </summary> /// <param name="item">指定ListImageItem</param> /// <returns></returns> public bool Contains(ListImageItem item) { return(InnerList.Contains(item)); }
/// <summary> /// 构造一参数对象 /// </summary> /// <param name="index"></param> /// <param name="item"></param> public ItemChangedEventArgs(int index, ListImageItem item) { _index = index; _item = item; }