newbie: How to set focus to TabPage?

D

deko

I need to open FormB from a menu selection on FormA, and set the focus to a
particular page in the TabControl on FormB.


private void mnuScheduler_Click(object sender, EventArgs e)
{
FormSettings FormSettings = new FormSettings();
FormSettings.ShowDialog();
// ok. the form is open.
// how do I set focus to a particular page in the TabControl on
FormSettings?
}

Thanks in advance.
 
B

Bruce Wood

You need to use the SelectedIndex property of the TabControl that owns
the TabPage:

this.tabControl1.SelectedIndex = 2; // Selects the third tab page
 
D

deko

You need to use the SelectedIndex property of the TabControl that owns
the TabPage:

this.tabControl1.SelectedIndex = 2; // Selects the third tab page

Well, I set the Modifiers property of the TabControl to Internal and tried
this:

private void mnuScheduler_Click(object sender, EventArgs e)
{
FormSettings FormSettings = new FormSettings();
FormSettings.ShowDialog();
FormSettings.tabSettings = new TabControl();
FormSettings.tabSettings.SelectedIndex = 2;
}

No luck. I could not find any property on the TabPage that specified the
index of the page. So I tried this:

private void mnuScheduler_Click(object sender, EventArgs e)
{
FormSettings FormSettings = new FormSettings();
FormSettings.Show();
Console.WriteLine(FormSettings.tabSettings.SelectedIndex);
}

and the output was -1

Why?

I also noticed that I did not get any output with this:

private void mnuScheduler_Click(object sender, EventArgs e)
{
FormSettings FormSettings = new FormSettings();
FormSettings.ShowDialog();
Console.WriteLine(FormSettings.tabSettings.SelectedIndex);
}

Is there something about opening the form in Dialog mode that prevents me
from programmatically setting the TabControl SelectedIndex?
 
D

deko

You need to use the SelectedIndex property of the TabControl that owns
the TabPage:

this.tabControl1.SelectedIndex = 2; // Selects the third tab page

Got this working:

private void mnuScheduler_Click(object sender, EventArgs e)
{
FormSettings FormSettings = new FormSettings();
FormSettings.tabSettings.SelectedIndex = 1;
FormSettings.ShowDialog();
}

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top