private void UpdateImageList()
{
IntPtr handle = IntPtr.Zero;
if (this.Style != CommandBarStyle.Menu)
{
Size size = new Size(8, 8);
for (int i = 0; i < items.Count; i++)
{
Image image = items[i].Image;
if (image != null)
{
if (image.Width > size.Width)
{
size.Width = image.Width;
}
if (image.Height > size.Height)
{
size.Height = image.Height;
}
}
}
Image[] images = new Image[items.Count];
for (int i = 0; i < items.Count; i++)
{
Image image = items[i].Image;
images[i] = (image != null) ? image : new Bitmap(size.Width, size.Height);
}
if (this.imageList == null)
{
this.imageList = new ImageList();
this.imageList.ImageSize = size;
this.imageList.ColorDepth = ColorDepth.Depth32Bit;
for (int i = 0; i < images.Length; i++)
{
this.imageList.Images.Add(images[i]);
}
}
else if (this.imageList.Images.Count == images.Length)
{
for (int i = 0; i < images.Length; i++)
{
this.imageList.Images[i] = images[i];
}
}
else
{
this.imageList.Images.Clear();
this.imageList.ImageSize = size;
for (int i = 0; i < images.Length; i++)
{
this.imageList.Images.Add(images[i]);
}
}
handle = this.imageList.Handle;
}
NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETIMAGELIST, 0, handle);
}