Autor Beitrag
Raven280438
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99



BeitragVerfasst: So 26.09.10 18:43 
Hi,

ich habe einen HauptForm, in dem durch einem Button ein anderes Form aufgerufen wird.
In diesem Form will ich Variablen im Haupt-Form ändern.
Wie bekomm ich das hin? Bin Anfänger ;)



Gruß
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mo 27.09.10 07:15 
Hallo,

Am besten gibts tu das Hauptformular bei der Erstellung des zweiten Formulars gleich im Konstruktor an und speicherst es dort dann als Feld:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
private Form1 mainForm;

public Form2(From1 mainForm) {
  this.mainForm = mainForm;

  InitializeComponents();
}


Grüße,
Yogu


Zuletzt bearbeitet von Yogu am Mo 27.09.10 19:27, insgesamt 1-mal bearbeitet
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4803
Erhaltene Danke: 1060

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 27.09.10 09:25 
Hallo Raven,

lies dir mal den bei www.c-sharp-forum.de....php?p=614082#614082 verlinkten Beitrag durch.

Und zu Yogu's Beitrag:
Es ist keine gute Idee, daß untergeordnete Forms Zugriff auf das Hauptformular (MainForm) erhalten, denn dadurch schafft man direkte Abhängigkeiten der beiden Forms.