Autor Beitrag
Doommortar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Di 18.08.09 17:40 
Hallo

Ich habe ein Hauptformular Form1 auf dem sich ein Button befindet. Wenn man auf dem Button klickt wird Form2 geladen.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
private void button1_Click(object sender, EventArgs e)
{
   Form2 f2 = new Form2();
   f2.ShowDialog(this);
}


Auf Form2 sind zwei Textfelder. Auf diese Textfelder möchte ich von Form3 zugreifen.

Habt ihr für mich ein Beispiel wie ich das machen muss? Vielen Dank schon mal. :D

Gruß Doommortar
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 18.08.09 18:04 
Such mal nach "Kommunikation 2 Forms"...

In einem anderen Forum gibt es dazu eine FAQ: www.mycsharp.de/wbb2...ad.php?threadid=5960
Doommortar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: So 23.08.09 17:05 
Hallo

Ich habe mir die FAQ durchgelesen. Leider klappt es noch nicht. :oops:

Ich habe 3 Formulare. Nachdem man in Form1 auf ein Button geklickt hat öffnet sich Form2 auf dem sich ein Textfeld befindet. Soweit funktioniert alles. Jetzt soll man über einen Button2 aus Form1 ein drittes Formular (Form3) öffnen können. In diesem Form3 soll der Inhalt, von dem Textfeld aus Form2, in einem Label ausgegeben werden.

Form1
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

        private void button2_Click(object sender, EventArgs e)
        {
            Form3 frm3 = new Form3();
            frm3.Show();
        }
    }
}



Form2
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
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 WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        private string UserName = "";
        public string User
        {
            get { return this.textBox1.Text; }            
            set { this.UserName = value; }
        }

        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text != null) { this.User = textBox1.Text; }
            this.Close(); 
        }
    }
}



Wie bekomme ich den Wert aus Form2 in Form3? was mache ich falsch? :roll:

Gruß Doommortar
JasonDelife
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81

Windows 7 Professional
C# (Visual Studio 2008 Professional), Java (NetBeans IDE 6.7)
BeitragVerfasst: So 23.08.09 19:23 
Ungefähr so (nur ein Ansatz):
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
// Form1
Form2 frm2 = new Form2();
frm2.UserInputChanged += frm2_UserInputChanged;
private void button1_Click(object sender, EventArgs e) {
 frm2.Show();
}

Form3 frm3 = new Form3()
private void button2_Click(object sender, EventArgs e) {
 frm3.Show();
}

private void frm2_UserInputChanged(object sender, EventArgs e) {
 frm3.MyProperty = frm2.UserInput;
}


Grüße, JasonDelife.