There is no built-in feature or functionality to track a control that targets a previous version. As you already mentioned, whenever a button is pressed, it will be in the spotlight. If you want to track a text field that has been focused before then, you will have to do it yourself.
One way to do this is to add a class level variable to the form containing a link to the current focused text field control:
private Control _focusedControl;
And then in the GotFocus event for each of your text field controls, you simply update the _focusedControl variable _focusedControl that text field:
private void TextBox_GotFocus(object sender, EventArgs e) { _focusedControl = (Control)sender; }
Now, whenever the button is clicked (why are you using the MouseDown event, as shown in the question, instead of the Click event button?), You can use the link to the previously configured text field control, which is stored in the class level variable, but you like:
private void button1_Click(object sender, EventArgs e) { if (_focusedControl != null) {
Cody gray
source share