using System; using System.Windows.Forms; public class FavoriteManager : UserControl { private ListBox listBox1; Favorite[] favs; public FavoriteManager() { InitializeComponent(); listBox1.DisplayMember = "Name"; } public void Add(string name, string url) { if (favs == null) { favs = new Favorite[] { new Favorite(name, new Uri(url)) }; listBox1.DataSource = favs; } else { Favorite[] favs2 = new Favorite[favs.Length + 1]; Array.Copy(favs, favs2, favs.Length); favs2[favs.Length] = new Favorite(name, new Uri(url)); favs = favs2; listBox1.DataSource = favs; } } public Favorite[] Favorites { set { favs = value; listBox1.DataSource = favs; } get { return favs; } } private void InitializeComponent() { this.listBox1 = new System.Windows.Forms.ListBox(); this.SuspendLayout(); // // listBox1 // this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.listBox1.FormattingEnabled = true; this.listBox1.Location = new System.Drawing.Point(0, 0); this.listBox1.Name = "listBox"; this.listBox1.Size = new System.Drawing.Size(150, 147); this.listBox1.TabIndex = 0; // // FavoriteManager // this.Controls.Add(this.listBox1); this.Name = "FavoriteManager"; this.ResumeLayout(false); } }