// On "Save" button - save kernel private void saveButton_Click(object sender, System.EventArgs e) { if (sfd.ShowDialog( ) == DialogResult.OK) { try { Serialize2DimArray.Save(sfd.FileName, kernel); } catch (ApplicationException) { MessageBox.Show(this, "Failed saving kernel to specified file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// On "Load" button - load kernel private void loadButton_Click(object sender, System.EventArgs e) { if (ofd.ShowDialog( ) == DialogResult.OK) { try { int[,] array = (int[, ])Serialize2DimArray.Load(ofd.FileName, typeof(int)); int size = array.GetLength(0); int i; // check size if (size != array.GetLength(1)) { throw new ApplicationException( ); } for (i = 0; i < sizes.Length; i++) { if (size == sizes[i]) { this.sizeCombo.SelectedIndex = i; break; } } if (i == sizes.Length) { throw new ApplicationException( ); } kernel = array; grid.LoadData(kernel); UpdateFilter( ); } catch (ApplicationException) { MessageBox.Show(this, "Failed loading kernel from specified file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }