Zitat:
Zitat von Technoskull
Du brauchst in der Form2 einen Zugriff auf Form1. Die kannst Du beim Erstellen von Form2 übergeben. Zum Beispiel so:
Schritt1:
Hinzufügen einer Property für die Zugriffsinstanz in Form2
Code:
public partial class Form2 : Form
{
private Form1 _parent;
public Form1 Parent1
{
get { return Parent; }
set { Parent = value; }
}
double Eingabe(TextBox tb)
{
....
Schritt2: Setzen der Property nach dem Erstellen von Form2
Code:
private void button6_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.ParentForm = this;
frm2.Show();
}
Danach kannst Du in Form2 folgenderweise auf Deine Textbox in Form1 zugreifen:
Code:public void button2_Click(object sender, EventArgs e)
{
double zahl1 = Eingabe(this.ParentForm1.textBox1);
double zahl2 = Eingabe(this.ParentForm1.textBox2);
//lblErgebnis.Text = Convert.ToString(zahl);
this.ParentForm1.label2.Text = Convert.ToString(zahl1 + zahl2);
}