Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text box that I want to set its focus
from inside mouse enter event.

But I failed to do that.

Please any help.

Thank you.

What I have tried:

private void InputTB_MouseEnter(object sender, EventArgs e)
{
  if (isRunning) return;
  if(languageCKB.Checked)
  {
    Application.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo(en_us));
    InputTB.RightToLeft = System.Windows.Forms.RightToLeft.No;
  }
  else
  {
    Application.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo(he_IL));
    InputTB.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
  }
    ActiveControl = InputTB;
    InputTB.TabIndex = 0;
    InputTB.Focus();
    InputTB.Select();
}
Posted
Updated 1-Apr-21 5:15am

1 solution

You are using Windows forms, so I just tried it: two text boxes, both handled by the same event handler:
C#
private void MyTextBoxes_MouseEnter(object sender, EventArgs e)
    {
    if (sender is TextBox tb)
        {
        tb.Focus();
        }
    }
And sure enough, it works: as the mouse moves between them, so does the input focus.

I'd suggest you use the debugger to see if isRunning is set when you don't think it should be.
 
Share this answer
 
Comments
Member 13569650 1-Apr-21 12:00pm    
Thank you.

You have helped me indirectly.

Thank you very much.
OriginalGriff 1-Apr-21 12:54pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900