In a C# 2010 desktop application, I would like to use the following code when
the user is selecting a file in a specified directory path:
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dialog.InitialDirectory = "C:";
dialog.Title = "Select a text file";
if (dialog.ShowDialog() == DialogResult.OK)
{
strPKGID = dialog.FileName;
}
I would like to use the above code in the following situations:
1. When the text box containing the file location loses focus and
2. When a submit button on the form is clicked.
Would you show me code for losing focus on the textbox and clicking the submit button?
Loading

VulpesRank #55 · 29.2K reputationPosted Jun 18, 2013, 4:37 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 17, 2013, 3:03 PM EDT
Do the same for the Click event of the submit button whose handler will look like this:
Now copy your code into these handlers or, alternatively, put it into a separate method and call the method from the handlers.
scampercat187 reputationPosted Jun 17, 2013, 7:28 PM EDT