private static void ImageListBox_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            e.ItemHeight = Consts.ImageListBoxItemMaxHeight + Consts.ImageListBoxItemImageMargin;

            var listBox = sender as ListBox;

            if (listBox == null)
            {
                return;
            }
            if (e.Index < 0)
            {
                return;
            }

            var item = listBox.Items[e.Index] as ImagedItem <FirmwareImageMetadata>;

            if (item == null)
            {
                return;
            }

            try
            {
                var cachedImage = ImageCacheManager.GetGlyphImage(item.ImageCacheIndex, item.Value.BlockType);
                e.ItemHeight = Math.Min(e.ItemHeight, cachedImage.Height + Consts.ImageListBoxItemImageMargin);
            }
            catch (ObjectDisposedException)
            {
                // Ignore
            }
        }
        private void ImageListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            var listBox = sender as ListBox;

            if (listBox == null)
            {
                return;
            }
            if (e.Index < 0)
            {
                return;
            }

            var item = listBox.Items[e.Index] as ImagedItem <FirmwareImageMetadata>;

            if (item == null)
            {
                return;
            }

            e.Graphics.SmoothingMode      = SmoothingMode.None;
            e.Graphics.InterpolationMode  = InterpolationMode.Low;
            e.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
            e.DrawBackground();

            var itemText = item.ToString();

            try
            {
                var imageScale = 1f;
                var image      = ImageCacheManager.GetGlyphImage(item.ImageCacheIndex, item.Value.BlockType);

                var greatestDimension = Math.Max(image.Width, image.Height);
                if (greatestDimension > Consts.ImageListBoxItemMaxHeight)
                {
                    imageScale = (float)greatestDimension / Consts.ImageListBoxItemMaxHeight;
                }

                var resultWidth  = image.Width / imageScale;
                var resultHeight = image.Height / imageScale;

                e.Graphics.DrawImage(image, e.Bounds.X + Consts.ImageListBoxItemImageMargin, e.Bounds.Y + (int)(e.Bounds.Height / 2f - resultHeight / 2f), resultWidth, resultHeight);
            }
            catch (ObjectDisposedException)
            {
                // Ignore
            }

            var stringRectX = e.Bounds.X + Consts.ImageListBoxItemMaxHeight + Consts.ImageListBoxItemImageMargin * 2;

            e.Graphics.DrawString(itemText, e.Font, new SolidBrush(e.ForeColor), new RectangleF(stringRectX, e.Bounds.Y, e.Bounds.Width - stringRectX - Consts.ImageListBoxItemImageMargin, e.Bounds.Height), m_listBoxStringFormat);
            e.DrawFocusRectangle();
        }
        private void Icb_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            e.ItemHeight = Consts.ImageListBoxItemMaxHeight + Consts.ImageListBoxItemImageMargin;

            var comboBox = sender as ComboBox;

            if (comboBox == null)
            {
                return;
            }
            if (e.Index < 0)
            {
                return;
            }

            var stringMetadata = comboBox.Tag as Tuple <FirmwareStringMetadata, int>;

            if (stringMetadata == null)
            {
                return;
            }

            var item = comboBox.Items[e.Index] as ImagedItem <byte>;

            if (item == null)
            {
                return;
            }

            try
            {
                var cachedImage = ImageCacheManager.GetGlyphImage(item.ImageCacheIndex, SelectedImageBlock);
                e.ItemHeight = Math.Min(e.ItemHeight, cachedImage.Height + Consts.ImageListBoxItemImageMargin);
            }
            catch (ObjectDisposedException)
            {
                // Ignore
            }
        }