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



BeitragVerfasst: Mo 26.09.11 10:38 
Hi,

ich habe nach Diesem Code-Schnipsel ein NotifyIcon-Programm zusammengebaut.
Ausserdem hab ich ein WinForm (Form1) welches ich bei einem Click auf ein MenuItem anzeigen möchte.
ausblenden C#-Quelltext
1:
2:
3:
4:
        private static void OnClickOpen(Object sender, EventArgs e)
        {
            new Form1().Show();
        }


Wie bekomm ich es jetzt hin, dass wenn das Fenster schon geöffnet ist, das Fenster einfach nur in den Fordergrund geholt wird und nicht immer ein Neues geöffnet wird?
Die Klasse Program ist ja static, da kann ich auch keine Member-Variable für Form1 nehmen.



Gruß
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: Mo 26.09.11 11:09 
Hallo Raven280438,

du kannst aber genauso eine statische Membervariable erstellen:
ausblenden C#-Quelltext
1:
static private Form1 myForm;					

Du müßtest dann beim Aufruf entsprechend auf 'null' prüfen.
Und dann müßtest du noch sicherstellen, daß entweder beim Schließen des Fensters (FormClosed-Ereignis) die Variable wieder zurückgesetzt wird, oder aber daß du nur das Fenster versteckst (Hide).
Raven280438 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99



BeitragVerfasst: Mo 26.09.11 11:16 
Hi,

danke für die Antwort.
Aber wie bekomm ich das hin, dass beim Schließen das Form wieder auf null gesetzt wird?
this = null; im FormClosing geht ja nicht...


Gruß
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mo 26.09.11 11:50 
Abonniere in der Program-Klasse FormClosed, denn in dessen Eventhandler hast du dann Zugriff auf myForm.

_________________
>λ=
Raven280438 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99



BeitragVerfasst: Mo 26.09.11 11:58 
Hi,

alles klar, habs hinbekommen ;)

Vielen Dank