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. use of information from a previous form

use of information from a previous form

Scheduled Pinned Locked Moved C#
question
5 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.
  • N Offline
    N Offline
    naghoumeh14
    wrote on last edited by
    #1

    let us consider we have two forms form1 and form2 and there are some information in form1 that i would like to use in form2... which method should i use to perform this action?

    S D 2 Replies Last reply
    0
    • N naghoumeh14

      let us consider we have two forms form1 and form2 and there are some information in form1 that i would like to use in form2... which method should i use to perform this action?

      S Offline
      S Offline
      sanforjackass
      wrote on last edited by
      #2

      if form1 create form2 then from form2 you can define a public var. like this: int x; public int X { set { x=value; } } then when you create you can send the var. like this: form2 f2=new form2(); f2.X=5; f2.show();

      N 1 Reply Last reply
      0
      • S sanforjackass

        if form1 create form2 then from form2 you can define a public var. like this: int x; public int X { set { x=value; } } then when you create you can send the var. like this: form2 f2=new form2(); f2.X=5; f2.show();

        N Offline
        N Offline
        naghoumeh14
        wrote on last edited by
        #3

        suppose we have a tab of buttons in form1 and i want to use the text of the clicked button in form2... how can i do such a thing?

        S 1 Reply Last reply
        0
        • N naghoumeh14

          let us consider we have two forms form1 and form2 and there are some information in form1 that i would like to use in form2... which method should i use to perform this action?

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          There are three obvious ways if Form1 is the parent. 1. Form1 sets a property in Form2 (as suggested above) 2. Form1 calls a method in Form2 3. Form2 raises a custom DataRequest event with custom EventArgs. Form1 subscribes to this and fills the event args accordingly when it handles the event. If Form2 is the parent form then a DataChanged event in Form1 and a suitable handler in Form2 is the way to go. If the hierachy is different, then a combination of the above up and down the hierachy will work. If that gets too complex then a separate manager class that routes events between the class instances can be useful.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          1 Reply Last reply
          0
          • N naghoumeh14

            suppose we have a tab of buttons in form1 and i want to use the text of the clicked button in form2... how can i do such a thing?

            S Offline
            S Offline
            sanforjackass
            wrote on last edited by
            #5

            use delegation: in form1 create textbox and put: public delegate void dd(string s); public static dd d; and put (d=new dd(write);) in public Form1() then write method (write): privet void write(string s) { textbox1.text=s; } in form2 create button and textbox then in click event put: Form1.d(textbox1);

            modified on Wednesday, January 20, 2010 6:53 PM

            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