Autor Beitrag
vreden123
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 95
Erhaltene Danke: 2



BeitragVerfasst: Mi 15.12.10 23:28 
hallo,

in meiner haupt Form habe ich folgende Variable:
string programmtitel = "name";

Wenn ich jetzt diese variable in der Infoform (andere Form) verwenden möchte, wie muss ich das machen?
Weil jetzt mekert er das die Variable im aktuellen Kontext nicht vorhanden wäre.
Namenlosnameless
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Do 16.12.10 00:27 
schau dir mal "public" an

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>
huuuuuh
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 665
Erhaltene Danke: 19

win xp, (win vista), win 7
VS 2008 Express Edition, VS 2010 Express Edition, VS 2010 Professionell
BeitragVerfasst: Do 16.12.10 07:52 
public? dann wäre die Variable in allen andern Klassen bekannt. (und statt ne Variable selbst public zu machen, macht man ne Property, welche man in andren Klassen verwendet ;)) soll sie das?
eine andre möglichkeit wäre, die variable im konstruktor der neuen Form zu übergeben...
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4807
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Do 16.12.10 11:13 
Zitat:

eine andre möglichkeit wäre, die variable im konstruktor der neuen Form zu übergeben...

eine bessere Möglichkeit ...
denn untergeordnete Forms bzw. Dialogs sollten niemals direkt auf die Hauptform zugreifen.

Die allerbeste Lösung ist jedoch:
Beim VS ist die "AboutBox" als Vorlage vorhanden, welche den Programmnamen aus der Assembly.cs liest, so daß du diesen gar nicht übergeben brauchst (auch Version, Beschreibung, Copyright kannst du entsprechend dort anpassen und zusätzlich noch ein Icon fest hinterlegen).

_________________
... denn die Kunst ist nur der Schein anders als der Rest zu sein.
Namenlosnameless
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Mi 22.12.10 12:34 
user profile iconhuuuuuh hat folgendes geschrieben Zum zitierten Posting springen:
public? dann wäre die Variable in allen andern Klassen bekannt. (und statt ne Variable selbst public zu machen, macht man ne Property, welche man in andren Klassen verwendet ;)) soll sie das?
eine andre möglichkeit wäre, die variable im konstruktor der neuen Form zu übergeben...


SChon klar.... aber: vreden123, ist anscheinend noch anfänger und public ist eindeutig die einfacste Möglichkeit

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>