Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. User Control

User Control

Scheduled Pinned Locked Moved C#
winformsquestion
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Biswajit Ghosh
    wrote on last edited by
    #1

    I am doing a project and I just created a user control(consist of text boxes, labels and combo boxes) that added in more than one tab pages. I am being able to add the user control in the tab pages. e.g. The same user control added in three tabpages. But I would like to save the value of the text boxes of the user controls added in the respective tab pages. how could i?

    C A L 3 Replies Last reply
    0
    • B Biswajit Ghosh

      I am doing a project and I just created a user control(consist of text boxes, labels and combo boxes) that added in more than one tab pages. I am being able to add the user control in the tab pages. e.g. The same user control added in three tabpages. But I would like to save the value of the text boxes of the user controls added in the respective tab pages. how could i?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      How do you mean - save to where ? To a file ? To each other ?

      Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

      B 2 Replies Last reply
      0
      • C Christian Graus

        How do you mean - save to where ? To a file ? To each other ?

        Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

        B Offline
        B Offline
        Biswajit Ghosh
        wrote on last edited by
        #3

        to save each other

        B 1 Reply Last reply
        0
        • B Biswajit Ghosh

          to save each other

          B Offline
          B Offline
          bobsugar222
          wrote on last edited by
          #4

          Expose the TextBox.Text property as a property of your UserControl. eg

          public string TextBoxText
          {
          get { return textBox1.Text; }
          set { textBox1.Text = value; }
          }

          B 1 Reply Last reply
          0
          • B Biswajit Ghosh

            I am doing a project and I just created a user control(consist of text boxes, labels and combo boxes) that added in more than one tab pages. I am being able to add the user control in the tab pages. e.g. The same user control added in three tabpages. But I would like to save the value of the text boxes of the user controls added in the respective tab pages. how could i?

            A Offline
            A Offline
            aSarafian
            wrote on last edited by
            #5

            You mean in each tab the value of the textbox to be always the same?

            B 1 Reply Last reply
            0
            • B Biswajit Ghosh

              I am doing a project and I just created a user control(consist of text boxes, labels and combo boxes) that added in more than one tab pages. I am being able to add the user control in the tab pages. e.g. The same user control added in three tabpages. But I would like to save the value of the text boxes of the user controls added in the respective tab pages. how could i?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              I have 4 different cases for you: If you need the same TextBox in each of your tab pages, you may consider adding one TextBox to the TabControl (i.e. outside the tab pages) rather than to each individual page. If you need the same TextBox on some of your tab pages, you may still put it on the tab control (outside the tab pages) and you could alter its Visible state according to which tab page is currently active. If you need the same TextBox on some of your tab pages, and the instances have identical properties (such as font, backcolor, location, size, etc), then I would use Visual Studio Designer to add such TextBox to one of the pages, then programmatically add the same instance of TextBox to the other relevant tab pages. Something like tabpage.Controls.Add(myExistingTextBoxFromTabPage1); Then there is no doubt whatever relevant tab page you select you would see the same TextBox content, since there is actually only one instance. This will save you a lot of code that would otherwise be needed to keep multiple TextBoxes in sync. If your TextBoxes have different attributes on different tab pages, more code will be unavoidable. :)

              Luc Pattyn

              B 1 Reply Last reply
              0
              • L Luc Pattyn

                I have 4 different cases for you: If you need the same TextBox in each of your tab pages, you may consider adding one TextBox to the TabControl (i.e. outside the tab pages) rather than to each individual page. If you need the same TextBox on some of your tab pages, you may still put it on the tab control (outside the tab pages) and you could alter its Visible state according to which tab page is currently active. If you need the same TextBox on some of your tab pages, and the instances have identical properties (such as font, backcolor, location, size, etc), then I would use Visual Studio Designer to add such TextBox to one of the pages, then programmatically add the same instance of TextBox to the other relevant tab pages. Something like tabpage.Controls.Add(myExistingTextBoxFromTabPage1); Then there is no doubt whatever relevant tab page you select you would see the same TextBox content, since there is actually only one instance. This will save you a lot of code that would otherwise be needed to keep multiple TextBoxes in sync. If your TextBoxes have different attributes on different tab pages, more code will be unavoidable. :)

                Luc Pattyn

                B Offline
                B Offline
                Biswajit Ghosh
                wrote on last edited by
                #7

                I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?

                L 1 Reply Last reply
                0
                • A aSarafian

                  You mean in each tab the value of the textbox to be always the same?

                  B Offline
                  B Offline
                  Biswajit Ghosh
                  wrote on last edited by
                  #8

                  I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?

                  A 1 Reply Last reply
                  0
                  • B bobsugar222

                    Expose the TextBox.Text property as a property of your UserControl. eg

                    public string TextBoxText
                    {
                    get { return textBox1.Text; }
                    set { textBox1.Text = value; }
                    }

                    B Offline
                    B Offline
                    Biswajit Ghosh
                    wrote on last edited by
                    #9

                    I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      How do you mean - save to where ? To a file ? To each other ?

                      Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                      B Offline
                      B Offline
                      Biswajit Ghosh
                      wrote on last edited by
                      #10

                      I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?

                      C 1 Reply Last reply
                      0
                      • B Biswajit Ghosh

                        I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #11

                        If you want them to all be the same, then make a static property that stores the string, and a static array of textboxes, which each textbox adds itself to.  Then, changing it in one instance, will change it in all. The other option is to set up a delegate, so each control lets the parent form know when it's changed, and it sets them all, with the sort of code you have above.

                        Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                        1 Reply Last reply
                        0
                        • B Biswajit Ghosh

                          I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?

                          A Offline
                          A Offline
                          aSarafian
                          wrote on last edited by
                          #12

                          I really can't understand what you are after! Also in your code snipets you have two sequencial commands that practically ony the second has meaning. By the way posting the same in two different persons trying to help and asking different questions is not the way.

                          1 Reply Last reply
                          0
                          • B Biswajit Ghosh

                            I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #13

                            Since you want the TextBox visible on each of the tab pages, I would go for one of these two possibilities: 1) -with Designer (or programmatically) add the TextBox on the first tab page (say it is named "textName1"), and leave the same place free on all other tab pages - programmatically add the SAME TextBox to the other tab pages. Something like:

                            bool firstPage=true;
                            foreach (TabPage page in myTabControl) {
                            if (!firstPage) page.Controls.Add(textName1);
                            firstPage=false;
                            }

                            Of course you could also use the tab page names explicitly:

                             tabPage2.Control.Add(textName1);
                             tabPage3.Control.Add(textName1);
                             tabPage4.Control.Add(textName1);
                            

                            or 2) do not add the TextBox to one or more tab pages, but add it to the form that is holding the tab control (not "to the tab control" as I had put in my previous post, that was slightly wrong, really to the form holding the tab control). In both cases, there is only one TextBox control, it is named textName1, so you have to set its text only once, have to save its text only once, etc. :)

                            Luc Pattyn

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups