同樣對 SelectedObjectCollection 進行包裝。
為支援圖示與多種顏色,加入以下成員:
private int _ImageIndex;
public int ImageIndex
{
get { return this._ImageIndex; }
set { this._ImageIndex = value; }
}
private Color _ForeColor;
public Color ForeColor
{
get { return this._ForeColor; }
set
{
this._ForeColor = value;
this.Parent.Invalidate(); // 顏色改變觸發重繪
}
}
private string _Text;
public string Text
{
get { return this._Text; }
set { this._Text = value; }
}
public override string ToString()
{
return this._Text;
}
DrawMode = DrawMode.OwnerDrawFixed;
private ListBoxExItemCollection _Items; // 建構函式中建立
new public ListBoxExItemCollection Items
{
get { return this._Items; }
}
new public ListBoxExItem SelectedItem // 強制轉換為 ListBoxExItem
{
get { return base.SelectedItem as ListBoxExItem; }
set { base.SelectedItem = value; }
}
new public SelectedListBoxExItemCollection SelectedItems // 重新包裝 SelectedItems
{
get { return new SelectedListBoxExItemCollection(base.SelectedItems); }
}
透過 new 關鍵字隱藏基類成員,提供強型別存取介面。