Reputation: 557
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?
Upvotes: 0
Views: 1308
Reputation: 599
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();
}
Upvotes: 0
Reputation: 880
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.
Upvotes: 1