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. Getting a value from another form

Getting a value from another form

Scheduled Pinned Locked Moved C#
helpquestion
7 Posts 6 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.
  • A Offline
    A Offline
    alee15 10 88
    wrote on last edited by
    #1

    Hi all, I have a textbox in Form1, where the user of the mentioned program is going to enter his name. Then I have another Form (Form2) in which I would like to display the name of the user by getting it from Form1. I am using MDI. Can I do it? If so, can you help me please! Thanks a lot for your help

    D S F L 4 Replies Last reply
    0
    • A alee15 10 88

      Hi all, I have a textbox in Form1, where the user of the mentioned program is going to enter his name. Then I have another Form (Form2) in which I would like to display the name of the user by getting it from Form1. I am using MDI. Can I do it? If so, can you help me please! Thanks a lot for your help

      D Offline
      D Offline
      Dy
      wrote on last edited by
      #2

      Either make the textbox in form 1 public, or define a property or function that's public to return the entered text. Then in form 2, you will be able to access it via the form 1 object. If you do not have a reference to the form 1 object in form 2, you won't be able to do that though.


      - Dy

      1 Reply Last reply
      0
      • A alee15 10 88

        Hi all, I have a textbox in Form1, where the user of the mentioned program is going to enter his name. Then I have another Form (Form2) in which I would like to display the name of the user by getting it from Form1. I am using MDI. Can I do it? If so, can you help me please! Thanks a lot for your help

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        Have a look at this[^] article. Regards Senthil _____________________________ My Blog | My Articles | My Flickr | WinMacro

        C 1 Reply Last reply
        0
        • A alee15 10 88

          Hi all, I have a textbox in Form1, where the user of the mentioned program is going to enter his name. Then I have another Form (Form2) in which I would like to display the name of the user by getting it from Form1. I am using MDI. Can I do it? If so, can you help me please! Thanks a lot for your help

          F Offline
          F Offline
          freshonlineMax
          wrote on last edited by
          #4

          Hello Let me help you about this public problem. 1.in Form1 go to code view page (press F7) 2.change below definition of textBox1: **private** System.Windows.Forms.TextBox textBox1; To : **public** static System.Windows.Forms.TextBox textBox1; 3.now if you build your project you got some errors as : ...cannot be accessed with an instance reference; ... and you should change all "this.textBox1" to "Form1.textBox1" like : **this**.textBox1 = new System.Windows.Forms.TextBox(); change to : **Form1**.textBox1 = new System.Windows.Forms.TextBox(); 3.go to Form2 and where you want to access Form1's textBox1 just use this : MessageBox.Show (**Form1.textBox1.Text**); Easy... mail me if you have problem yet :-D -- modified at 11:14 Monday 8th May, 2006

          C 1 Reply Last reply
          0
          • A alee15 10 88

            Hi all, I have a textbox in Form1, where the user of the mentioned program is going to enter his name. Then I have another Form (Form2) in which I would like to display the name of the user by getting it from Form1. I am using MDI. Can I do it? If so, can you help me please! Thanks a lot for your help

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            Look up the Model View Controler design pattern. Views should not know about each other. Forms are Views in this case.


            "What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum led mike

            1 Reply Last reply
            0
            • F freshonlineMax

              Hello Let me help you about this public problem. 1.in Form1 go to code view page (press F7) 2.change below definition of textBox1: **private** System.Windows.Forms.TextBox textBox1; To : **public** static System.Windows.Forms.TextBox textBox1; 3.now if you build your project you got some errors as : ...cannot be accessed with an instance reference; ... and you should change all "this.textBox1" to "Form1.textBox1" like : **this**.textBox1 = new System.Windows.Forms.TextBox(); change to : **Form1**.textBox1 = new System.Windows.Forms.TextBox(); 3.go to Form2 and where you want to access Form1's textBox1 just use this : MessageBox.Show (**Form1.textBox1.Text**); Easy... mail me if you have problem yet :-D -- modified at 11:14 Monday 8th May, 2006

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              freshonlineMax wrote:

              change below definition of textBox1: private System.Windows.Forms.TextBox textBox1; To : public static System.Windows.Forms.TextBox textBox1;

              :omg: Why make fields in a class private, why not make them public?[^]


              "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

              1 Reply Last reply
              0
              • S S Senthil Kumar

                Have a look at this[^] article. Regards Senthil _____________________________ My Blog | My Articles | My Flickr | WinMacro

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #7

                :-> Thanks for plugging my article :-D


                "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

                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