Hi there. I was wondering how on earth do I transfer information from Form1 to Form2. For example, like, I type in form1 textbox "hello there" and in form2, if it is open, it will dis play ''hello there'' in its textbox or in a message box, something like that. But you understand what I am asking for though, right? =]

So just simple information like that. I think it's possible =o
I'm just planning on testing a bunch of functions with user input and displaying it on the opposite form. Thanks a bunch for the help!!

Form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace daniweb.formtalking
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      Form2 frm = FindOpenForm2();
      if (frm != null)
        frm.SetText(textBox1.Text);
    }

    private static Form2 FindOpenForm2()
    {
      for (int i1 = 0; i1 < Application.OpenForms.Count; i1++)
      {
        Form2 frm = (Application.OpenForms[i1] as Form2);
        if ((frm != null) && !frm.IsDisposed)
          return frm;
      }
      return null;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      new Form2().Show();
    }
  }
}

Form2:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace daniweb.formtalking
{
  public partial class Form2 : Form
  {
    public Form2()
    {
      InitializeComponent();
    }
    public void SetText(string text)
    {
      textBox1.Text = text;
    }
  }
}

cool thanks

You're welcome :)

Please mark this thread as solved if you have found an answer to your original question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.