private void btnPickFile_Click(object sender, EventArgs e) { var result = iconPickerDialog.ShowDialog(this); if (result == DialogResult.OK) { var fileName = iconPickerDialog.FileName; m_iconIndex = iconPickerDialog.IconIndex; Icon icon = null; Icon[] splitIcons = null; try { if (Path.GetExtension(iconPickerDialog.FileName).ToLower() == ".ico") { m_iconExtractor = null; icon = new Icon(iconPickerDialog.FileName); } else { m_iconExtractor = new IconExtractor(fileName); icon = m_iconExtractor.GetIcon(m_iconIndex); } splitIcons = IconUtil.Split(icon); } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } txtFileName.Text = String.Format( "{0}, #{1}, {2} variations", fileName, m_iconIndex, splitIcons.Length); // Update icons. Icon = icon; icon.Dispose(); lvwIcons.BeginUpdate(); ClearAllIcons(); foreach (var i in splitIcons) { var item = new IconListViewItem(); var size = i.Size; item.BitCount = IconUtil.GetBitCount(i); item.Bitmap = IconUtil.ToBitmap(i); item.ToolTipText = String.Format("{0}x{1}, {2} bits", size.Width, size.Height, item.BitCount); i.Dispose(); lvwIcons.Items.Add(item); } lvwIcons.EndUpdate(); btnSaveAsIco.Enabled = (m_iconExtractor != null); } }