Common method of using tab control?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett Romero

    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_Cli ck(object sender, EventArgs e)
    {
    if(tabControl1. SelectedIndex == 0)
    {...do something...}
    else if (tabControl1.Se lectedIndex == 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

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Common method of using tab control?

    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]
    - mvp@spam.guard. caspershouse.co m

    "Brett Romero" <account@cygen. com> wrote in message
    news:1137618713 .610610.18340@g 44g2000cwa.goog legroups.com...[color=blue]
    >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_Cli ck(object sender, EventArgs e)
    > {
    > if(tabControl1. SelectedIndex == 0)
    > {...do something...}
    > else if (tabControl1.Se lectedIndex == 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
    >[/color]


    Comment

    • Brett Romero

      #3
      Re: Common method of using tab control?

      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

      Comment

      • Mihaly

        #4
        RE: Common method of using tab control?

        You can use the TabControl's SelectedIndexCh anged event, or the TabPage's
        Click event.
        I supose you can use somthing like:

        private void tabControl1_Sel ectedIndexChang ed(
        object sender,
        System.EventArg s e)
        {
        if (this.tabContro l1.SelectedTab. Equals(this.tab Page1))
        {
        // do somthing...
        }
        else if (this.tabContro l1.SelectedTab. Equals(this.tab Page2))
        {
        // do somthing...
        }
        }

        Mihaly

        "Brett Romero" wrote:
        [color=blue]
        > 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_Cli ck(object sender, EventArgs e)
        > {
        > if(tabControl1. SelectedIndex == 0)
        > {...do something...}
        > else if (tabControl1.Se lectedIndex == 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
        >
        >[/color]

        Comment

        Working...