You could try testing the Focused property of the controls collection
foreach (Control z in this.Controls)
{
if (z is TextBox && z.Focused)
((TextBox)(z)).Paste();
}
However this could become more complicated if the TextBox are contained inside different GroupBoxes or other control containers.
In that case you need a recursive function
private void PasteInFocusedTextBox(ControlCollection ctrls)
{
foreach (Control z in ctrls)
{
if(z.Controls != null && z.Controls.Count > 1)
PasteInFocusedTextBox(z.Controls);
if (z is TextBox && z.Focused)
((TextBox)(z)).Paste();
}
}
EDIT: Rereading your question I have a doubt. If you click a button to execute the paste operation, then the focus will be switched to that button and you can no more use the focused property
In this case you need to save in a global var the last textbox with focus before the click on the command button
private TextBox _txtLastFocused = null
private void txtCommon_Leave(object sender, EventArgs e)
{
_txtLastFocused = (TextBox)sender;
}
private void cmdPasteButton_Click(object sender, EventArgs e)
{
if(_txtLastFocused != null) _txtLastFocused.Paste();
}