Question

I have several tabs in a form. Each tab has one textbox. When I enter tabpage1 I have managed to set the focus on the textBox1. When I press a button in tabpage1 I jump to a random tab in the controller. What I want now is to have the focus set on textBox in the active tabpage. I have tried using tabpage_Enter event, but it does not seem to work. My code look like this :

    private void tabPage2_Enter(object sender, EventArgs e)
    {
        textBox2.Select();

    }

Any suggestions?

Was it helpful?

Solution

I think you need to use SelectedIndexChanged event of TabControl instead of _Enter, using Enter event, focus will change to textBox2 every time the cursor enter the tabPage control.

OTHER TIPS

You can use the Focus() method set the focus on a textbox. I would probably set on the tabPage_Enter event.

private void tabPage_Enter(object sender, EventArgs e){
{
    var tab = sender as tabPage;
    if(!tab.Focused) tab.focus();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top