-1

I have the TextBox eingabe in my form3 Now my plan is to save the TextBox eingabe as a String and than give out the String on my form4 How is this possible? I tried:

//form3.cs    
    public partial class Form3 : Form
{
    public Form3()
    {
        InitializeComponent();
    }

    private void eingabe_TextChanged(object sender, EventArgs e)
    {

    }

    private void openWindow(object sender, EventArgs e)
    {
        this.Hide();
        Form4 form4 = new Form4();
        form4.ShowDialog();
        String help = eingabe.Text;
    }
}

//form4.cs
    public partial class Form4 : Form
{
    public Form4()
    {
        InitializeComponent();
    }

    private void Form4_Load(object sender, EventArgs e)
    {
        ausgabe = help;
    }

    private void ausgabe_Click(object sender, EventArgs e)
    {

    }
}

That doesn't work. Please don't judge me I am new to all this...

janne
  • 79
  • 6

3 Answers3

1

Write code like below on Form3:

inputtext= eingabe.text

Make Form4 constructor parametrized and pass inputtext value to Form4 as argument in Form4 object.

Another way : Create a public property on Form4 lets say you have X property on Form4. set X value as below on Form3

objectForm4.X=eingabe.text
Always_a_learner
  • 1,254
  • 1
  • 8
  • 16
0

First you have to get the text (eingabe.Text) then send it to new form when navigate to new form

cemozkan
  • 11
  • 1
  • Like this? `//form3.cs string help = eingabe.Text //form4.cs Properties.Settings.Default.help= eingabe.Text;` – janne May 05 '20 at 11:42
0

I found the solution:

    public static string help;

    private void openWindow(object sender, EventArgs e)
    {
        help = eingabe.Text;

        this.Hide();
        Form4 form4 = new Form4();
        form4.ShowDialog();
    }

And in Form 4:

    private void Form4_Load(object sender, EventArgs e)
    {
        ausgabe.Text = Form3.help;
    }
janne
  • 79
  • 6
  • Ok, so it helps you at the moment. But do you realize, if there is no instance of form3, the code in form4 will not work as you expect. Maybe you should consider having some "global" available object for holding data like this. – nabuchodonossor May 05 '20 at 13:42