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:
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.
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.