Results 1 to 2 of 2

Thread: [RESOLVED] passing data between forms

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Resolved [RESOLVED] passing data between forms

    Hello guys.

    I have a rather easy problem that I myself Can't fix, but I'm sure you guys can help me with it.

    I have two forms in a project, form1 and form2. Now what I want is to call form2 from form1, and then send a value from form2 to the instance of form1 that's already open.

    The way I know how to do this is with a constructor, but then I'd have to call another instance of form1. I could solve it by closing it after calling form2, that would be one solution, but not the one I'm looking for. Now, can anyone help?

    The value I want from form2 must land in a textBox in form1.

    Thank you guys.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: passing data between forms

    Okay, I already solved it thanks to jmcilhinney postings in another thread.

    Code in case anyone wants to see.

    Code:
    public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            private Form1 F1;
            public Form2(Form1 f1)
            {
    
                InitializeComponent();
                this.F1 = f1;
            
            }
    
               
            private void button1_Click(object sender, EventArgs e)
            {
                string th = textBox1.Text;
                F1.get(th);
                           
            }
    
    
    
            
    
        }
    Code:
     public Form1()
            {
                InitializeComponent();
            }
    
            public void get(string tomar)
            {
                textBox1.Text = tomar;
            }
            
            private Form2 frm;
    
            private void button1_Click(object sender, EventArgs e)
            {
                frm = new Form2(this);
                frm.Show();
    
                
    
            }
    
            
        }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width