submit button and textbox

jassie

Well-known member
Joined
Nov 13, 2012
Messages
61
Programming Experience
1-3
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?
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,151
Location
Sydney, Australia
Programming Experience
10+
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