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. Passing data between forms

Passing data between forms

Scheduled Pinned Locked Moved C#
3 Posts 3 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.
  • P Offline
    P Offline
    pj4FarEweDsf
    wrote on last edited by
    #1

    Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1

    M J 2 Replies Last reply
    0
    • P pj4FarEweDsf

      Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1

      M Offline
      M Offline
      Meysam Mahfouzi
      wrote on last edited by
      #2

      Pass an instance of Form1 to constructor of Form2 when instanciating, something like this:

      Form2 frm2 = new Form2(this);

      Then in Form2, you have access to all public and internal variables of Form1, so you can define a property of your Lable1 in Form1:

      public string MyLable{
      get{
      return this.Lable1.Text;
      }
      set{
      }
      this.Lable1.Text = value;
      }

      and in Form2, when the user clicks on Button1, do this:

      frm1.MyLable = TextBox1.Text;

      frm1 is a variable of type Form1 that holds a refrence to Form1 which has been passed to constructor of Form2. abcdabcdabcdabcda Don't forget, that's

      Persian Gulf

      not Arabian gulf!


      Why do we close our eyes, when we dream?, When we cry?, When we imagine?, When we kiss?, Its because the most beautiful things in the world are unseen


      Murphy:
      Click Here![^]


      I'm thirsty like sun, more landless than wind...

      1 Reply Last reply
      0
      • P pj4FarEweDsf

        Looking for code to pass information from Form2.textbox1 back to Form1.label1 Process - Press Form1.button1 to show Form2, Enter information into Form2.textbox1, Press Form2.button1 to display information from Form2.textbox1 to Form1.label1. Thnaks in Advance! Form1 consists of Label1 Button1 For2 consist of textbox1 Button1

        J Offline
        J Offline
        Jeff Varszegi
        wrote on last edited by
        #3

        Google on "Mediator pattern" and "MVC" (or "Model-View-Controller"). If you learn how to use these patterns, you'll never get stuck like this again; your code won't need tricks like passing a form to another form. I recommend "Design Patterns" by the Gang of Four. I'm not saying maysam's advice is bad, but as you construct more and more complicated GUIs, you'll find that it's harder and harder to deal with the complexity you create by hard-wiring things together. Design patterns are over-applied and otherwise screwed up by morons who haven't taken the time to really learn how to use them, which has given them a bad rap. In my experience, though, Mediator and MVC are the most important things to know when programming client-side rich GUI applications. Everything else is a little bit of learning involving threads that's easy to accomplish, and rote memorization of properties of controls and the like.

        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