Autor Beitrag
C#
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: Do 06.10.11 22:59 
Hallo,

da sich wenn man bei C# die Startform schließt, das Programm schließt, kann ich meine Form1 nicht schließen, was ich aber tun sollte.
Jetzt habe ich eine Neue Form erstellt (FormsControl). Diese ist permanent im unsichtbar und dient nur zur Kontrolle der anderen Formen.
wenn ich jetzt von dort aus die 1. Form starte, also:
ausblenden C#-Quelltext
1:
2:
LogIn loginForm = new LogIn();
loginForm.Show();

sieht dass bei mir so aus (siehe Anhang). Und mehr geht nicht.
Woran kann das liegen?
Ach ja, meine FormsControl Form springt danach in eine Endlosschleife.
Einloggen, um Attachments anzusehen!
_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler
daeve
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 116
Erhaltene Danke: 3

Windows (XP Pro, 7 Ultimate x64)
C#,WPF,Java,ASP.Net, VS 2010 Ultimate (x86)
BeitragVerfasst: Fr 07.10.11 00:17 
Bin nicht sicher was du meinst aber wenn dein Problem ist das keine Komponenten sichtbar sind, musst du die Methode Initialize() aufrufen.
Und wiso eine unsichtbare Form zur Kontrolle ??
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: Fr 07.10.11 11:03 
Hallo C#,

du hast anscheinend deine GUI blockiert (daher wird keine Message mehr intern abgearbeitet).

Wenn du einen Login-Dialog vor deiner eigentlichen Hauptform anzeigen lassen willst, dann benutze dafür ShowDialog (diese verwendet eine eigene Message-Schleife).
Am besten du rufst diesen Login-Dialog dann in der Main-Methode auf:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
static void Main()
{
  LogIn loginDlg = new LogIn();
  if (loginDlg.ShowDialog() == DialogResult.OK)
  {
     Application.Run(new MainForm());
  }
}

Evtl. noch um Passwort-Abfrage (o.ä.) ergänzen und in einer Schleife abarbeiten (oder aber alles im Login-Dialog abfragen).

Für diesen Beitrag haben gedankt: C#
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: Fr 07.10.11 11:28 
Zitat:
Jetzt habe ich eine Neue Form erstellt (FormsControl). Diese ist permanent im unsichtbar und dient nur zur Kontrolle der anderen Formen.


Du musst Application.Run nicht zwingend mit einer Form aufrufen. In deinem Fall erscheint es sinnvoller dafür eine ApplicationContext Klasse zu benutzen anstatt einer unsichtbaren Form.

Für diesen Beitrag haben gedankt: C#
C# Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: Fr 07.10.11 17:02 
Vielen Dank für die Antworten. Habs jetzt mit einer Kombination aus beidem geschafft:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
class _Forms : ApplicationContext
    {
        public static string CurrentUser { get; set; }
        public _Forms()
        {
            LogIn loginForm = new LogIn();
            MainForm mainForm = new MainForm();

            //Now the loop starts which control the Froms
            while (true)
            {
                DialogResult res = loginForm.ShowDialog();
                if (res != DialogResult.OK) break;
                mainForm.user = CurrentUser;
                res = mainForm.ShowDialog();
                if (res == DialogResult.Retry) continue;
                if (res == DialogResult.Cancel) break;
            }
            Application.Exit();
        }

    }

Funktioniert prima.

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler