From 90a3bfe87f627f4599919a2e0c20badc6cd4229f Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 5 Jul 2019 22:51:00 +0100 Subject: [PATCH] Better use of OpenFileDialog --- src/flash-multi/FlashMulti.cs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/flash-multi/FlashMulti.cs b/src/flash-multi/FlashMulti.cs index 02fc201..f0b0861 100644 --- a/src/flash-multi/FlashMulti.cs +++ b/src/flash-multi/FlashMulti.cs @@ -457,30 +457,21 @@ private void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine) private void ButtonBrowse_Click(object sender, EventArgs e) { // Create the file open dialog - OpenFileDialog openFileDialog = new OpenFileDialog + using (OpenFileDialog openFileDialog = new OpenFileDialog()) { // Title for the dialog - Title = "Choose file to flash", + openFileDialog.Title = "Choose file to flash"; // Filter for .bin files - Filter = ".bin File|*.bin" - }; + openFileDialog.Filter = ".bin File|*.bin"; - try - { - // Show the dialog - openFileDialog.ShowDialog(); - - // Set the text box to the selected file name - textFileName.Text = openFileDialog.FileName; - } catch (Exception ex) - { - MessageBox.Show(String.Format("Error selecting file: {0}", ex.Message), "Select File", MessageBoxButtons.OK, MessageBoxIcon.Error); + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + // Set the text box to the selected file name + textFileName.Text = openFileDialog.FileName; + } } - // Dispose the file open dialog - openFileDialog.Dispose(); - // Check if the Upload button should be enabled yet CheckControls(); }