tabpage clone

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

    #1

    tabpage clone

    Hi,
    I've a tabcontrol that contains many similar tabpages (exactly the same
    structure with different information), the tabpages number isn't known in
    the design time it depends of the data.
    Is there a way to clone ( copy the structure) a tabpage to create anew one
    by code?
    thanks.


  • Fergus Cooney

    #2
    Re: tabpage clone

    Hi Touf,

    || Is there a way to clone (copy the structure) a tabpage to
    || create a new one by code?

    Can you tell me what controls you have on your TabPages? Also, what,
    specifically, do you want to do with the new TabPage?

    Regards,
    Fergus


    Comment

    • touf

      #3
      Re: tabpage clone

      thanks Fergus
      I like to display statistic for cutomers
      for each customer I create a new TabPage that contain :
      - a label and a textBox that contains the customer name
      - a listBox that contain the total of the sales by year.

      I've created the first TabPage in the design view, and I like to create the
      others by code.


      "Fergus Cooney" <filter-1@tesco.net> wrote in message
      news:ufypsHfiDH A.1872@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi Touf,
      >
      > || Is there a way to clone (copy the structure) a tabpage to
      > || create a new one by code?
      >
      > Can you tell me what controls you have on your TabPages? Also, what,
      > specifically, do you want to do with the new TabPage?
      >
      > Regards,
      > Fergus
      >
      >[/color]


      Comment

      • Armin Zingler

        #4
        Re: tabpage clone

        "touf" <toufik_i@hotma il.com> schrieb[color=blue]
        > thanks Fergus
        > I like to display statistic for cutomers
        > for each customer I create a new TabPage that contain :
        > - a label and a textBox that contains the customer name
        > - a listBox that contain the total of the sales by year.
        >
        > I've created the first TabPage in the design view, and I like to
        > create the others by code.[/color]

        I'd create them all by code. I'd probably derive my own class from Tabpage
        and create a new instance per customer. To save some work, you could move
        the code, generated by the designer for your already existing tabpage, to
        you derived TabPage.


        --
        Armin

        Comment

        • Fergus Cooney

          #5
          Re: tabpage clone

          Hi Touf,

          There is nothing in .NET to clone a Control and its children so it all has
          to be done 'manually'. It <is> possible to do it with Reflection and recursion
          but I think that would be overkill in this case.Thankfully , it sounds as if
          your TabPages aren't too complicated.

          What I recommend is that you look in the Windows Form Designer code
          section and simply copy out the parts that created your first TabPage. Stick
          these into a separate routine and add the appropriate parameters for things
          like label captions, etc..

          The event handling has to be added explicitly using AddHandler. With a
          Designer-added Control, event handling is done for you, so you get:
          Sub Button1_Click (sender, e) Handles Button1.Click.
          You'll need to do
          AddHandler ButtonX.Click, AddressOf Button1_Click
          This will make Button1 and ButtonX go to the same routine for their
          Clicks, so you may need to determine which one is being pressed - this will be
          the sender argument.

          Have a look at the example below which creates a new TabPage with a Label,
          a TextBox and a Button. Note how these controls are added to the TabPage and
          then the TabPage is added to the TabControl.

          SuspendLayout() and ResumeLayout() are in comments. They prevent
          flickering by stopping the TabControl from drawing itself unti the new
          Tabpages have been added. You may not need to call these but if you do, that's
          where they go.

          Come back if you need further help with this. :-)

          Regards,
          Fergus

          <code>
          Private Sub AddTabPage (... <Text values, etc> ...)
          Dim LabelX As New Label
          Dim TextBoxX As New TextBox
          Dim ButtonX As New Button

          'A new Label
          LabelX.Location = New System.Drawing. Point(39, 56)
          LabelX.Name = "LabelX"
          LabelX.TabIndex = 4
          LabelX.Text = "LabelX"

          'And a new TextBox
          TextBoxX.Locati on = New System.Drawing. Point(31, 20)
          TextBoxX.Name = "TextBoxX"
          TextBoxX.TabInd ex = 3
          TextBoxX.Text = "TextBoxX"

          'And a new Button
          ButtonX.Locatio n = New System.Drawing. Point(159, 28)
          ButtonX.Name = "ButtonX"
          ButtonX.TabInde x = 5
          ButtonX.Text = "ButtonX"
          AddHandler ButtonX.Click, AddressOf Button1_Click

          'And a new TabPage to put them on.
          Dim TabPageX As New TabPage
          TabPageX.Locati on = New System.Drawing. Point(4, 22)
          TabPageX.Name = "TabPageX"
          TabPageX.Size = New System.Drawing. Size(264, 98)
          TabPageX.TabInd ex = 0
          TabPageX.Text = "TabPageX"

          'Add the controls to the TabPage.
          TabPageX.Contro ls.AddRange _
          (Control() {LabelX, TextBoxX, ButtonX})

          'Add the TabPage to the TabControl.
          'Me.TabControl1 .SuspendLayout( )
          Me.TabControl1. Controls.Add (TabPageX)
          'Me.TabControl1 .ResumeLayout(F alse)

          'Bring the new TabPage to the front.
          TabControl1.Sel ectedTab = TabPageX
          End Sub
          </code>


          Comment

          • Versteijn

            #6
            Re: tabpage clone

            "touf" <toufik_i@hotma il.com> wrote in message news:<um0RCZbiD HA.1688@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
            > Hi,
            > I've a tabcontrol that contains many similar tabpages (exactly the same
            > structure with different information), the tabpages number isn't known in
            > the design time it depends of the data.
            > Is there a way to clone ( copy the structure) a tabpage to create anew one
            > by code?
            > thanks.[/color]

            One option is to create a custom control (class), i.e. your tabpage
            with the needed controls on it.

            Good luck

            Freek Versteijn

            Comment

            • Fergus Cooney

              #7
              Re: tabpage clone

              Hi Touf, Freek,

              And a damn fine suggestion , too! For if you have a UserControl and change
              the layout or what-have-you, it will work for all of the TabPages. Whereas, if
              you go the make-a-copy route that I showed you earlier, you will have more
              work to do every time your design changes. It depends on which is easier and
              how stable your UI design is.

              Regards,
              Fergus


              Comment

              • touf

                #8
                Re: tabpage clone

                Thans friends,
                I think that the best way I have, is to move the code of the designer to a
                sub and call it with parameters...


                "Fergus Cooney" <filter-1@tesco.net> wrote in message
                news:uqAy5qmiDH A.616@TK2MSFTNG P11.phx.gbl...[color=blue]
                > Hi Touf, Freek,
                >
                > And a damn fine suggestion , too! For if you have a UserControl and[/color]
                change[color=blue]
                > the layout or what-have-you, it will work for all of the TabPages.[/color]
                Whereas, if[color=blue]
                > you go the make-a-copy route that I showed you earlier, you will have more
                > work to do every time your design changes. It depends on which is easier[/color]
                and[color=blue]
                > how stable your UI design is.
                >
                > Regards,
                > Fergus
                >
                >[/color]


                Comment

                • yanike
                  New Member
                  • Jul 2006
                  • 1

                  #9
                  Originally posted by Fergus Cooney
                  Hi Touf, Freek,

                  And a damn fine suggestion , too! For if you have a UserControl and change
                  the layout or what-have-you, it will work for all of the TabPages. Whereas, if
                  you go the make-a-copy route that I showed you earlier, you will have more
                  work to do every time your design changes. It depends on which is easier and
                  how stable your UI design is.

                  Regards,
                  Fergus
                  THANK YOU THANK YOU THANK YOU!!!!

                  This is exactly what I was looking for :)

                  Comment

                  Working...