Autor Beitrag
Syra
Hält's aus hier
Beiträge: 13

Windows 7 Ultimate x64
Visual C# 2010/Visual Studio 2012
BeitragVerfasst: So 06.10.13 16:01 
Hallo,

ich versuche grade eine art Accounttool (Zum speichern von Passwörtern etc, halt zu lernzwecken) zu erstellen.
Jedoch habe ich das Problem, Dass ich die Werte aus der Variable von Form2 an die Listbox von Form1 übergeben muss, jedoch sagt mir die Entwicklungsumgebung "Für das nicht statische Feld, die Methode oder die Eigenschaft "WindowsFormsApplication1.Form1.listBox1" ist ein Objektverweis erforderlich.".

Um die Listbox anzusprechen nutze ich folgenden Code:
ausblenden C#-Quelltext
1:
Form1.listBox1.Add("accountID");					

Ich bräuchte nur helfe um die listBox anzusprechen.

Lg :)

Moderiert von user profile iconTh69: C#-Tags hinzugefügt
Moderiert von user profile iconTh69: Topic aus C# - Die Sprache verschoben am Mo 07.10.2013 um 08:57
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: So 06.10.13 16:24 
Form1 ist eine Klasse du brauchst aber einen Verweis auf eine bestimmte Instanz von Form1. Wenn die Form2 Instanz aus einer Form1 Instanz erzeugt hast solltest du diese konkrete Form1 an Form2 übergeben. Z.B über den Konstruktor oder eine Property oder .... egal wie Form2 braucht eine Referenz auf die konkrete Form1.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4805
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 07.10.13 08:03 
Hallo Syra,

in Ergänzung dazu noch: schau dir mal die Antwort von Christian in Steuerelemente aus einem anderen Form ansprechen sowie meinen dort verlinkten Artikel zur "Kommunikation von 2 Forms" an.