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
33
34
35
36
37
38
39
40
41
42
43
44
45
|
//Code Form1
//===========
Form2 f2 = new Form2(this); // neue Instanz von Typ Form2 erstellen mit Übergabe der eigenen Referenz
f2.Show(); // neue form Anzeigen
//Übergeben eines strings von Form1 zu Form2
f2.TextBoxForm2 = "Hallo Welt";
//Property die das Lesen und Schreiben des TextBox Inhaltes ermöglicht
public string TextBoxForm1
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
// Code Form2
//===========
Form AufrufendeForm; // Globale Variable im Form2
public Form2(Form f) // Konstruktor
{
InitializeComponent();
AufrufendeForm = f; // Zuordnung der Referenz
}
// Übergeben eines Strings von Form2 zu Form1
((Form1)AufrufendeForm).TextBoxForm1 = "Hallo Welt";
//Property die das Lesen und Schreiben des TextBox Inhaltes ermöglicht
public string TextBoxForm2
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
|