private void gifPart_ValueChanged(object sender, EventArgs e) { UpdatePreview(); GifPart part = (sender as IGifCtrl).GifPart; ListViewItem item = null; foreach (ListViewItem i in lstParts.Items) { if (i.Tag == part) { item = i; break; } } if (item != null) { UpdateListViewItem(item, part); } }
private void UpdateListViewItem(ListViewItem item, GifPart part) { if (part is GifPartHeader) { item.Text = "Header"; item.ImageIndex = 0; } else if (part is GifPartLwzImage) { GifPartLwzImage img = part as GifPartLwzImage; item.Text = string.Format("Image [{0}x{1} @{2}x{3}]", img.Width, img.Height, img.Left, img.Top); item.ImageIndex = 1; } else if (part is GifPartMetaData.ApplicationData) { GifPartMetaData.ApplicationData app = part as GifPartMetaData.ApplicationData; item.Text = string.Format("AppData [{0}]", app.AppIdentifier); item.ImageIndex = 2; } else if (part is GifPartMetaData.Loop) { GifPartMetaData.Loop loop = part as GifPartMetaData.Loop; item.Text = string.Format("AppData [Repeat: {0}]", loop.Iterations); item.ImageIndex = 2; } else if (part is GifPartMetaData.Comment) { GifPartMetaData.Comment cmt = part as GifPartMetaData.Comment; item.Text = string.Format("Comment [{0} bytes]", cmt.Content.Length); item.ImageIndex = 3; } else if (part is GifPartMetaData.GraphicsControl) { GifPartMetaData.GraphicsControl ctrl = part as GifPartMetaData.GraphicsControl; item.Text = string.Format("Control [Trans:{0}, Delay:{1}]", ctrl.UseTransparency ? "1" : "0", ctrl.UseUserInput ? "User" : ((ctrl.DelayTime).ToString() + "ms")); item.ImageIndex = 4; } else if (part is GifPartMetaData.TextDraw) { GifPartMetaData.TextDraw txt = part as GifPartMetaData.TextDraw; string txtt = txt.Text; item.Text = string.Format("Text [{2}, @{0}x{1}]", txt.Left, txt.Width, txtt.Length > 10 ? (txtt.Substring(0, 8) + "...") : txtt); item.ImageIndex = 5; } else if (part is GifPartMetaData) { GifPartMetaData mta = part as GifPartMetaData; item.Text = string.Format("Unknown [{0}]", mta.MetaType); item.ImageIndex = 6; } else if (part is GifPartTerminator) { item.Text = "EOF"; item.ImageIndex = 7; } else if (part is GifPartGarbageData) { GifPartGarbageData grb = part as GifPartGarbageData; item.Text = "Garbage data"; item.ImageIndex = 8; } }
private void UpdateExistingList() { if (this.InvokeRequired) { this.Invoke(new Action(UpdateList)); return; } SuspendLayout(); ListViewItem item; for (int i = 0; i < _wrapper.Count; i++) { GifPart part = _wrapper[i]; if (lstParts.Items.Count <= i) { // Item count too low -> Append new item item = new ListViewItem(); UpdateListViewItem(item, _wrapper[i]); item.SubItems.Add(_wrapper[i].Length.ToString()); item.Tag = _wrapper[i]; lstParts.Items.Add(item); } else if (lstParts.Items[i].Tag != _wrapper[i]) { // Item at this position does not match -> ... #region Find item index int index = -1; for (int x = 0; x < lstParts.Items.Count; x++) { if (lstParts.Items[x].Tag == part) { index = x; break; } } #endregion if (index == -1) { // The item is not included yet -> Insert new item item = new ListViewItem(); UpdateListViewItem(item, _wrapper[i]); item.SubItems.Add(_wrapper[i].Length.ToString()); item.Tag = _wrapper[i]; lstParts.Items.Insert(i, item); } else { // Item found at a different location -> Update and relocated item = lstParts.Items[index]; UpdateListViewItem(item, part); lstParts.Items.RemoveAt(index); lstParts.Items.Insert(i, item); } } else { // Correct item at the correct position -> Update item = lstParts.Items[i]; UpdateListViewItem(item, part); } } ResumeLayout(); }