Autor Beitrag
Xzeer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 62



BeitragVerfasst: Sa 12.12.09 15:54 
Hallo,

Ich habe ein Problem dabei, mein Programm direkt minimiert im Systemtray zu starten.

Ich benutze ein NotifyIcon dazu um mein Programm in den Tray zu minimieren. Der Code dazu sieht so aus:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
        private void Main_Resize(object sender, EventArgs e)
        {
            if (basic.holeConfigEintragAlsBool("InDenTrayMinimieren"))
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    notifyIconMain.Visible = true;
                    this.Hide();
                }
            }
        }

        private void toolStripMenuItemTrayÖffnen_Click(object sender, EventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            notifyIconMain.Visible = false;
        }


Funktioniert auch so ohne Probleme.

Wenn ich in der Form_Load Methode versuche das Programm in den Tray zu schicken, geht das nicht.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
                if (this.WindowState == FormWindowState.Minimized)
                {
                    notifyIconMain.Visible = true;
                    this.Hide();
                }


Mir ist auch klar warum, aber ich habe gerade keine andere Idee das Problem zu lösen.

Muss ich dafür ein anderes Ereignis nehmen, oder wie kann ich das schaffen? Ich könnte auch einen Timer nehmen, halte das aber eher für unsauber.

_________________
Xzeer
Xzeer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 62



BeitragVerfasst: Mi 16.12.09 17:34 
kenn da niemand eine bessere lösung, als einen timer zu verwenden, der die anwendung nach einiger zeit in den systray schiebt?

_________________
Xzeer
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 19.12.09 18:55 
Hallo!

Ich benutze nicht die Visible-Eigenschaft der Form, sondern die ShowInTaskbar-Eigenschaft. Die setze ich bereits im Designer(!) auf false, ebenso setze ich dort den WindowState bereits auf minimized. Und dort mache ich dann auch direkt das TrayIcon sichtbar.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".