private void SetDFImageFile(DFImageFile ImageFile)
        {
            // Handle null
            if (null == ImageFile)
            {
                MyDFImageFile = null;
                this.Refresh();
                return;
            }

            // Store file object
            MyDFImageFile = ImageFile;

            // Build layout array
            BuildLayoutArray();

            // Reset scroll bar
            ResetScrollBars();
            UpdateScroller();

            // Recalculate layout
            UpdateFlowLayout();

            // Update scrolling
            UpdateScroller();

            // Force view redraw
            this.Refresh();
        }
        static void Main(string[] args)
        {
            // Specify Arena2 path of local Daggerfall installation
            string MyArena2Path = "C:\\dosgames\\DAGGER\\ARENA2";

            // Instantiate ImageFileReader
            ImageFileReader MyImageFileReader = new ImageFileReader(MyArena2Path);

            // Set desired library type
            MyImageFileReader.LibraryType = LibraryTypes.Texture;

            // Load TEXTURE.285 file
            MyImageFileReader.LoadFile("TEXTURE.285");

            // Output some information about this file
            Console.WriteLine("Image file {0} has {1} records",
                              MyImageFileReader.FileName,
                              MyImageFileReader.RecordCount);

            // Get image file to work with
            DFImageFile imageFile = MyImageFileReader.ImageFile;

            // Loop through all records
            for (int r = 0; r < imageFile.RecordCount; r++)
            {
                // Output some information about this record
                int  frameCount = imageFile.GetFrameCount(r);
                Size sz         = imageFile.GetSize(r);
                Console.WriteLine("Record {0} has {1} frames and is {2}x{3} pixels",
                                  r, frameCount,
                                  sz.Width,
                                  sz.Height);

                // Get first frame of record as a managed bitmap
                Bitmap managedBitmap = imageFile.GetManagedBitmap(r, 0, true, false);
            }
        }
        private void BuildLayoutArray()
        {
            // Exit if image file not set
            if (null == MyDFImageFile)
            {
                return;
            }

            // Count total image items from all records and frames
            int ItemCount = 0;

            for (int record = 0; record < MyDFImageFile.RecordCount; record++)
            {
                if (!IsAnimatedValue)
                {
                    // Count each frame as an item if not animated
                    int frameCount = MyDFImageFile.GetFrameCount(record);
                    for (int frame = 0; frame < frameCount; frame++)
                    {
                        ItemCount++;
                    }
                }
                else
                {
                    // Just increment count
                    ItemCount++;
                }
            }

            // Create layout array
            MyLayout = new LayoutItem[ItemCount];

            // Add bitmaps to layout array
            int curItem = 0;

            for (int record = 0; record < MyDFImageFile.RecordCount; record++)
            {
                // Get frame count and skip record with zero frames (no image)
                int FrameCount = MyDFImageFile.GetFrameCount(record);
                if (0 == FrameCount)
                {
                    continue;
                }

                if (AnimateImages && FrameCount > 1)
                {
                    // Create managed bitmap array
                    MyLayout[curItem].ManagedBitmaps = new Bitmap[FrameCount];

                    // Add all frames
                    for (int frame = 0; frame < FrameCount; frame++)
                    {
                        MyLayout[curItem].ManagedBitmaps[frame] = DFImageFile.GetManagedBitmap(record, frame, false, Transparency);
                    }

                    // Store details
                    MyLayout[curItem].IsAnimated   = true;
                    MyLayout[curItem].Record       = record;
                    MyLayout[curItem].Frame        = -1;
                    MyLayout[curItem].FrameCount   = FrameCount;
                    MyLayout[curItem].CurrentFrame = 0;

                    // Increment
                    curItem++;
                }
                else
                {
                    // Create new layout item
                    MyLayout[curItem] = new LayoutItem();

                    // Add each frame as a single item
                    for (int frame = 0; frame < FrameCount; frame++)
                    {
                        // Create managed bitmap array
                        MyLayout[curItem].ManagedBitmaps = new Bitmap[1];

                        // Get single frame
                        Bitmap bitmap = DFImageFile.GetManagedBitmap(record, frame, false, Transparency);

                        // Store details
                        MyLayout[curItem].IsAnimated        = false;
                        MyLayout[curItem].ManagedBitmaps[0] = bitmap;
                        MyLayout[curItem].Record            = record;
                        MyLayout[curItem].Frame             = frame;
                        MyLayout[curItem].FrameCount        = FrameCount;
                        MyLayout[curItem].CurrentFrame      = 0;

                        // Increment
                        curItem++;
                    }
                }
            }

            // Reset mouse over and selected indices
            MyMouseOverIndex = -1;
            MySelectedIndex  = -1;
            RaiseSelectedImageChangedEvent();
        }