private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.DefaultExt = "pal"; openFileDialog.Filter = "Palette Files (SCI or Microsfot RIFF)|*.pal"; openFileDialog.Multiselect = false; openFileDialog.Title = "Select a SCI or Microsoft Palette."; DialogResult r = openFileDialog.ShowDialog(); if (r == System.Windows.Forms.DialogResult.Cancel) { return; } if (File.Exists(openFileDialog.FileName)) { try { byte[] buffer = File.ReadAllBytes(openFileDialog.FileName); PalType type = PaletteTools.GetType(buffer); paletteControl1.CellWidth = 25; paletteControl1.CellHeight = 25; paletteControl1.FontSize = 4; paletteControl1.ShowPalette(PaletteTools.Load(buffer, type)); paletteControl1.Refresh(); } catch (Exception ex) { MessageBox.Show(string.Format("{0} : {1}", ex.Message, ex.StackTrace)); } } else { MessageBox.Show("Unknown Error"); } }
/// <summary> /// Opens and loads selected PAL file in the palBox /// </summary> private void OpenPal() { if (File.Exists(palFile)) { palette.Clear(); try { byte[] buffer = File.ReadAllBytes(palFile); PalType type = PaletteTools.GetType(buffer); if (type == PalType.Unknown) { MessageBox.Show(string.Format("Unknown Type {0}", BitConverter.ToInt32(buffer, 0).ToString("X2"))); return; } LoadedColors = PaletteTools.Load(buffer, type); palInfoLbl.Text = string.Format("Palette type - {0}, {1} Colors", type, LoadedColors.Length); this.Text = defaultTxt + " - " + palFile; paletteControl1.ShowPalette(LoadedColors); ShowPalette(LoadedColors); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Unknown Error"); } // Enable save if (picBox.Image != null) { saveAsBtn.Enabled = true; saveAsFileMenu.Enabled = true; } else { saveAsBtn.Enabled = false; saveAsFileMenu.Enabled = false; } }
/// <summary> /// Opens and loads selected PAL file in the palBox /// </summary> private void OpenPal(string palFile) { if (File.Exists(palFile)) { this.PaletteRects.Clear(); try { byte[] buffer = File.ReadAllBytes(palFile); PalType type = PaletteTools.GetType(buffer); if (type == PalType.Unknown) { MessageBox.Show(string.Format("Unknown Type {0}", BitConverter.ToInt32(buffer, 0).ToString("X2"))); return; } this.CurrentLoadedType = type; ShowPalette(PaletteTools.Load(buffer, type)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Unknown Error"); } }