Form.Show() and TabControl tab page changed
-
I have the following problem -I created a form with an tab control -I the tab control contains (minimum) 2 tab pages -In the second (non selected) tab page i have a control -And there is another formular (irrelevant content)
#region PREPERATION // instanciate a form Form f = new Form(); // instanciate a tab control TabControl t = new TabControl(); // instanciate tab page 1 TabPage tp1 = new TabPage("page1"); // instanciate tab page 2 TabPage tp2 = new TabPage("page2"); // instanciate a control (sample: button) Button b = new Button(); b.Size = new Size(100, 20); // add the control to the tab page tp2.Controls.Add(b); // add the tab pages t.TabPages.Add(tp1); t.TabPages.Add(tp2); // add the tabcontrol this.Controls.Add(t); t.BringToFront(); #endregion PREPERATION
When i first open the child-form with Show() and then select the tab page with the control the parent-form is focused again.// show the form f.Show(); // select the tab with the control t.SelectedIndex = 1;
How can i force the child-form to keep its focus, while the parent change the tab page? I don't want to use ShowDialog() or Show(this). Is this a bug or a feature of the tab control (tab page)? (Is the only way to fix it, changing the order of the source code?) -
I have the following problem -I created a form with an tab control -I the tab control contains (minimum) 2 tab pages -In the second (non selected) tab page i have a control -And there is another formular (irrelevant content)
#region PREPERATION // instanciate a form Form f = new Form(); // instanciate a tab control TabControl t = new TabControl(); // instanciate tab page 1 TabPage tp1 = new TabPage("page1"); // instanciate tab page 2 TabPage tp2 = new TabPage("page2"); // instanciate a control (sample: button) Button b = new Button(); b.Size = new Size(100, 20); // add the control to the tab page tp2.Controls.Add(b); // add the tab pages t.TabPages.Add(tp1); t.TabPages.Add(tp2); // add the tabcontrol this.Controls.Add(t); t.BringToFront(); #endregion PREPERATION
When i first open the child-form with Show() and then select the tab page with the control the parent-form is focused again.// show the form f.Show(); // select the tab with the control t.SelectedIndex = 1;
How can i force the child-form to keep its focus, while the parent change the tab page? I don't want to use ShowDialog() or Show(this). Is this a bug or a feature of the tab control (tab page)? (Is the only way to fix it, changing the order of the source code?) -
Try tp2.Select(); You don't want to select the tab control, but the actual tab with the control on it. Hogan
-
I have the following problem -I created a form with an tab control -I the tab control contains (minimum) 2 tab pages -In the second (non selected) tab page i have a control -And there is another formular (irrelevant content)
#region PREPERATION // instanciate a form Form f = new Form(); // instanciate a tab control TabControl t = new TabControl(); // instanciate tab page 1 TabPage tp1 = new TabPage("page1"); // instanciate tab page 2 TabPage tp2 = new TabPage("page2"); // instanciate a control (sample: button) Button b = new Button(); b.Size = new Size(100, 20); // add the control to the tab page tp2.Controls.Add(b); // add the tab pages t.TabPages.Add(tp1); t.TabPages.Add(tp2); // add the tabcontrol this.Controls.Add(t); t.BringToFront(); #endregion PREPERATION
When i first open the child-form with Show() and then select the tab page with the control the parent-form is focused again.// show the form f.Show(); // select the tab with the control t.SelectedIndex = 1;
How can i force the child-form to keep its focus, while the parent change the tab page? I don't want to use ShowDialog() or Show(this). Is this a bug or a feature of the tab control (tab page)? (Is the only way to fix it, changing the order of the source code?)