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. How can I get input from 2 forms?

How can I get input from 2 forms?

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

    Hi, I have two forms that both open windows, I need to get the response from a checkbox on Form2 and use it with Form1, Form2 is not a dialogue and needs to open all the time. Any ideas? Thanks.

    C D N 3 Replies Last reply
    0
    • C CopperCircle

      Hi, I have two forms that both open windows, I need to get the response from a checkbox on Form2 and use it with Form1, Form2 is not a dialogue and needs to open all the time. Any ideas? Thanks.

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

      Delegates.

      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

      1 Reply Last reply
      0
      • C CopperCircle

        Hi, I have two forms that both open windows, I need to get the response from a checkbox on Form2 and use it with Form1, Form2 is not a dialogue and needs to open all the time. Any ideas? Thanks.

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

        As Christian said - use delegates. Simple example I've given before here[^]. Edited link!

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Expect everything to be hard and then enjoy the things that come easy. (code-frog)

        modified on Friday, August 22, 2008 3:23 AM

        I 1 Reply Last reply
        0
        • C CopperCircle

          Hi, I have two forms that both open windows, I need to get the response from a checkbox on Form2 and use it with Form1, Form2 is not a dialogue and needs to open all the time. Any ideas? Thanks.

          N Offline
          N Offline
          nelsonpaixao
          wrote on last edited by
          #4

          Create 1 form & 1 userform a couple of buttons etc,etc , put the userform inside the form and check this out ok?! I think you can read the code bellow. :-O ///////////////////////////////////////////// public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { userControl11.MyTextEvent += new UserControl1.MyDelegate(userControl11_TextEvent); userControl11.visibility_ev += new UserControl1.MyDelegate2(userControl11_visibility); } protected void userControl11_TextEvent(string textToSet) { textBox1.Text = textToSet; } protected void userControl11_visibility(bool visibility_b) { textBox1.Visible = visibility_b; } } /////////////////////////////////// public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public delegate void MyDelegate(string textToSet); public event MyDelegate MyTextEvent; private void button1_Click(object sender, EventArgs e) { if (MyTextEvent != null) //Checks if anyone has registered the event. MyTextEvent("This is a sample text"); } public delegate void MyDelegate2(bool visibility_dl); public event MyDelegate2 visibility_ev; private void button2_Click(object sender, EventArgs e) { if (button2.Text == "Hide") { visibility_ev(false); button2.Text = "Show"; } else { visibility_ev(true); button2.Text = "Hide"; } } } //////////////////////////////////////////

          nelsonpaixao@yahoo.com.br

          S 1 Reply Last reply
          0
          • D DaveyM69

            As Christian said - use delegates. Simple example I've given before here[^]. Edited link!

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Expect everything to be hard and then enjoy the things that come easy. (code-frog)

            modified on Friday, August 22, 2008 3:23 AM

            I Offline
            I Offline
            ianhunt01
            wrote on last edited by
            #5

            The link "Here" leads nowhere ?

            D 1 Reply Last reply
            0
            • N nelsonpaixao

              Create 1 form & 1 userform a couple of buttons etc,etc , put the userform inside the form and check this out ok?! I think you can read the code bellow. :-O ///////////////////////////////////////////// public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { userControl11.MyTextEvent += new UserControl1.MyDelegate(userControl11_TextEvent); userControl11.visibility_ev += new UserControl1.MyDelegate2(userControl11_visibility); } protected void userControl11_TextEvent(string textToSet) { textBox1.Text = textToSet; } protected void userControl11_visibility(bool visibility_b) { textBox1.Visible = visibility_b; } } /////////////////////////////////// public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public delegate void MyDelegate(string textToSet); public event MyDelegate MyTextEvent; private void button1_Click(object sender, EventArgs e) { if (MyTextEvent != null) //Checks if anyone has registered the event. MyTextEvent("This is a sample text"); } public delegate void MyDelegate2(bool visibility_dl); public event MyDelegate2 visibility_ev; private void button2_Click(object sender, EventArgs e) { if (button2.Text == "Hide") { visibility_ev(false); button2.Text = "Show"; } else { visibility_ev(true); button2.Text = "Hide"; } } } //////////////////////////////////////////

              nelsonpaixao@yahoo.com.br

              S Offline
              S Offline
              Silvyster
              wrote on last edited by
              #6

              no need for delegates, if form 1 called form 2 and you have problems passing values from form 2 to form 1 just make accessor methods from form 2 that after form 2 is closed, you can get the values from form 2.. you can also make use of again accessor methods if you want to pass values from form 1 to form 2 that before showing form2, set first the values then show form 2

              N 1 Reply Last reply
              0
              • I ianhunt01

                The link "Here" leads nowhere ?

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

                Edited the link - thanks for pointing it out.

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Expect everything to be hard and then enjoy the things that come easy. (code-frog)

                1 Reply Last reply
                0
                • S Silvyster

                  no need for delegates, if form 1 called form 2 and you have problems passing values from form 2 to form 1 just make accessor methods from form 2 that after form 2 is closed, you can get the values from form 2.. you can also make use of again accessor methods if you want to pass values from form 1 to form 2 that before showing form2, set first the values then show form 2

                  N Offline
                  N Offline
                  nelsonpaixao
                  wrote on last edited by
                  #8

                  don´t use 2 forms, use 1 form and load userforms inside, like what i showed you before. I would use many form, for exemple, if i wanted to create a chat application (to load private chat windows). But ... you are the boss :-D i don´t know what you are trying to achieve. Good Luck :cool:

                  nelsonpaixao@yahoo.com.br

                  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