submit button and textbox


Well-known member
Nov 13, 2012
Programming Experience
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?
All you have to do is handle the appropriate events. Double-click the Button to create an event handler for its Click event and put your code in it. You can then select the TextBox, open the Properties window, click the Events button and then select the event handler you just created in the drop-down for the Leave event.
Top Bottom