Home > Back-end >  How do I restore focus to previously focused control of the TabPage when switching between tabs
How do I restore focus to previously focused control of the TabPage when switching between tabs

Time:05-10

I have a TabControl and I'm adding Tabpages to it programmatically. Each TabPage loads a UserControl in it, and each user control contains a few controls. For example:

TabPage1
   UserControl1
      TextBox1, TextBox2, TextBox3
TabPage2
   UserControl2
      TextBox4, TextBox5, TextBox6

Now I want that whenever the user changes the tab, the previously-focused control of that tab get focus again when the tab is selected again.

Example:

  1. Let's say the focus is on TabPage1 → UserControl1 → TextBox2
  2. Then I click on TagPage 2 → UserControl2 → TextBox4
  3. Then I again click on TabPage1 and I want TextBox2 get the focus.

What shall I do?

CodePudding user response:

Possible solution:

Override TabControl TabPage restore ActiveControl

  • Related