471,570 Members | 942 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Common method of using tab control?

I have a tab control with seven tabs. I need to do certain things when
a user clicks each tab. I'm doing this:

private void tabControl1_Click(object sender, EventArgs e)
{
if(tabControl1.SelectedIndex == 0)
{...do something...}
else if (tabControl1.SelectedIndex == 6)
{...do something...}
.....
}

and so on for all tabs. That or switches will work but isn't very
intuitive. Is there some other common way of doing this?

Thanks,
Brett

Jan 18 '06 #1
3 2943
Brett,

That's really the only way of doing it, really. You could perform an if
statement on the text of the tab, assuming that it is unique.

Is there some other way you were hoping to be able to do it?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I have a tab control with seven tabs. I need to do certain things when
a user clicks each tab. I'm doing this:

private void tabControl1_Click(object sender, EventArgs e)
{
if(tabControl1.SelectedIndex == 0)
{...do something...}
else if (tabControl1.SelectedIndex == 6)
{...do something...}
....
}

and so on for all tabs. That or switches will work but isn't very
intuitive. Is there some other common way of doing this?

Thanks,
Brett

Jan 18 '06 #2
I wasn't sure what else may be available for the tabcontrol in this
scenario. I just don't see all of those if statements or their
cousins, switches, as an elegant solution. That's all.

Thanks,
Brett

Jan 18 '06 #3
You can use the TabControl's SelectedIndexChanged event, or the TabPage's
Click event.
I supose you can use somthing like:

private void tabControl1_SelectedIndexChanged(
object sender,
System.EventArgs e)
{
if (this.tabControl1.SelectedTab.Equals(this.tabPage1 ))
{
// do somthing...
}
else if (this.tabControl1.SelectedTab.Equals(this.tabPage2 ))
{
// do somthing...
}
}

Mihaly

"Brett Romero" wrote:
I have a tab control with seven tabs. I need to do certain things when
a user clicks each tab. I'm doing this:

private void tabControl1_Click(object sender, EventArgs e)
{
if(tabControl1.SelectedIndex == 0)
{...do something...}
else if (tabControl1.SelectedIndex == 6)
{...do something...}
.....
}

and so on for all tabs. That or switches will work but isn't very
intuitive. Is there some other common way of doing this?

Thanks,
Brett

Jan 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Frank Esser | last post: by
11 posts views Thread by stax | last post: by
1 post views Thread by Ben | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.