Sauron
Sauron

Reputation: 16903

Focus the controls in a Tabcontrol

How can focus the controls when select a tabitem in a tabcontrol?

Upvotes: 0

Views: 1055

Answers (2)

Reputation:

You should capture the Selection changed event of the TabControl and inside that you focus the control you need. Just as

private void TabControl1_SelectionChanged(object sender, EventArgs e)
{
    control1.Focus();
}

Upvotes: 1

Nick Spacek
Nick Spacek

Reputation: 4773

Not sure I understand what you're asking completely, but you probably want to capture the SelectionChanged event for the TabControl:


public Window1()
{
  InitializeComponent();

  TabControl1.SelectionChanged += TabControl1_SelectionChanged;
}

private void TabControl1_SelectionChanged(object sender, EventArgs e)
{
  TabItem item = (TabItem)TabControl1.SelectedItem;
  // Find the first control in the TabItem content and focus it?
}

Upvotes: 1

Related Questions