Reputation: 781
I want my application to minimize to the system tray, and not be visible on the taskbar. I followed the suggestions from this and this answer and changed the MainFormOnTaskBar
property in the project source:
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.MainFormOnTaskBar := False;
Application.Run;
end.
Next I tried this:
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.Hide;
WindowState := wsMinimized;
TrayIcon1.Visible := True;
end;
and this variant:
procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
Self.Hide;
WindowState := wsMinimized;
TrayIcon1.Visible := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Minimize;
end;
but while the tray icon shows correctly the application still shows in the taskbar. What am I doing wrong?
Upvotes: 2
Views: 3541
Reputation: 781
David suggests that what I see in the taskbar is not my main form, but my application. Following his advice I hid that using ShowWindow
:
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.Hide;
WindowState := wsMinimized;
TrayIcon1.Visible := True;
ShowWindow(Application.Handle, SW_Hide);
end;
Problem solved. Thanks, David.
Upvotes: 2