private void frmGfxImportDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                GfxImportSettings g = new GfxImportSettings(
                    new FormParams(this.Location, new Size(), FormWindowState.Normal, null),
                    chkTileset.Checked,
                    chkFlips.Checked,
                    chkPal.Checked,
                    chkTransparent.Checked,
                    lblTransparent.BackColor);

                M3Settings.MainSettings.GfxImportSettings = g;
            }
        }
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (dlgImport.ShowDialog() == DialogResult.OK)
            {
                Bitmap bmp = new Bitmap(dlgImport.FileName);
                if ((bmp.Width != (arrWidth << 3)) || (bmp.Height != (arrHeight << 3)))
                {
                    MessageBox.Show("The image is the wrong size. It's " + bmp.Width + "x" + bmp.Height +
                                    ", but it should be " + (arrWidth << 3) + "x" + (arrHeight << 3) + ".",
                                    "Wrong size");
                    return;
                }

                // Prompt for options
                var          f   = new frmGfxImportDialog();
                DialogResult res = f.ShowDialog();
                if (res != DialogResult.OK)
                {
                    return;
                }

                GfxImportSettings g = M3Settings.MainSettings.GfxImportSettings;

                try
                {
                    object[] o = GfxProvider.SetArrangement(bmp, Tileset, 0, (EditLimit == -1) ?
                                                            TileCount : EditLimit,
                                                            g.UseTileset,
                                                            g.UseFlips,
                                                            g.UsePalette ? Palette.Entries[CurrentPalette] : null,
                                                            g.UsePalette ? CurrentPalette : 0,
                                                            g.TransparentColor,
                                                            g.UseTransparency
                                                            );

                    // Success!
                    Arrangement = (ArrEntry[])o[0];
                    Palette.Entries[CurrentPalette] = (Color[])o[1];

                    int colorsDropped = (int)o[2];
                    if (colorsDropped > 0)
                    {
                        MessageBox.Show("There were too many colors in the image, so only the 15 most common ones were preserved." +
                                        Environment.NewLine + colorsDropped + " color(s) were dropped.", "Too many colors");
                    }

                    SetPalette(Palette);

                    RenderTileset();
                    RenderTile();
                    RenderArr();

                    RefreshTileset();
                    RefreshTile();
                    RefreshArr();
                }
                catch (TileCountException ee)
                {
                    MessageBox.Show("This image needs " +
                                    ee.Tilecount + " tiles, but we only have room for " + ee.Tilelimit +
                                    " tiles.", "Too many tiles");
                }
                catch (TileMismatchException ee)
                {
                    MessageBox.Show("This image contains tiles not in the current tileset." +
                                    Environment.NewLine + "The problematic tile is at (" + (ee.TileX << 3) + ", " +
                                    (ee.TileY << 3) + ").",
                                    "No tile match");
                }

                f.Dispose();
                bmp.Dispose();
            }
        }