Autor Beitrag
snowy1980
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Do 07.05.09 14:34 
Hallo,

Auf Form1 liegt eine Listbox, dazu habe ich in Form1.cs eine Funktion die eine übergebene Variable in die Listbox schreibt.

Jetzt möchte ich von einer anderen Klasse einen Wert an diese Funktion geben damit dieser in der Listbox erscheint.

Wie mach ich das?
Nemag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 132
Erhaltene Danke: 2



BeitragVerfasst: Do 07.05.09 14:42 
Naja wenn du eine Instanz deiner Form1 in deiner zweiten Klasse anlegst oder übergibst oder whatauchever und deine Methode public ist dann kannst du diese ganz einfach aufrufen:


ausblenden C#-Quelltext
1:
2:
Form1 frm = new Form1();
frm.Methode(Variable);
snowy1980 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Do 07.05.09 14:50 
genau das funktioniert eben nicht.Da würde ich ja eine neue Form anlegen!

theoretisch müsste ich ja ds mit events programmieren. Geht das nicht auch leichter?
Nemag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 132
Erhaltene Danke: 2



BeitragVerfasst: Do 07.05.09 17:27 
Ich sag mal ohne eine genaue Struktur ist das hier jetzt nur Rätsel raten!

Aber du kannst in deiner zweiten Klasse auch sowas machen

ausblenden C#-Quelltext
1:
2:
3:
Form1 frm = VorhandenenForm <- 
//Wo auch immer die herkommt, du musst Sie ja nicht neu erstellen
frm.Methode(Variable)



Du musst Sie ja nicht neu erstellen.
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Do 07.05.09 18:01 
Ich hatte dich heute früh schon auf [FAQ] Kommunikation von 2 Forms; hingewiesen. Was gefällt dir daran nicht (abgesehen davon, dass es sich natürlich um umfangreiche Hinweise handelt)? Jürgen