How to SendKeys
to the last active input TextBox
after clicking a button in winforms (C#)? I'm new to C# and I'm trying to create a winforms application with an on-screen keyboard and I have multiple textboxes.
I have searched and tried the guides I found, here's sample that's working so far.
below code is working when I focused the cursor outside (notepad, etc) my winforms app, but when I click on my created TextBox
within the winforms app and then click a button to SendKeys
to the TextBox
, the cursor is being removed and focus is on the button I clicked, that is making the TextBox
unfocused.
const uint WS_EX_NOACTIVATE = 0x08000000;
const uint WS_EX_TOPMOST = 0x00000008;
protected override CreateParams CreateParams
{
get
{
CreateParams param = base.CreateParams;
param.ExStyle |= (int)(WS_EX_NOACTIVATE | WS_EX_TOPMOST);
return param;
}
}
private void btnA_Click(object sender, EventArgs e)
{
SendKeys.Send("A");
}
How can I return the cursor focus to the last active TextBox
when I click a button to SendKeys
to the TextBox
?.