Systray icon: click to open form?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Systray icon: click to open form?

Post by stevens »

Hi,

I would like to have an icon in systray for my project.
When clicked on the icon the form should appear, when clicked again it should dissapear.

I'd hope also it would be possible to not have the form minimized in taskbar: just the icon, click on it and the form is there, click again and it is gone (but systray icon stays there).

Tried to make the project into an exe, then not output form but systray. It works, but I cannot make any action happen when I click on the icon in the systray icon.

Hope this is clear.
Thanks for your help!
S
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Systray icon: click to open form?

Post by brittneyr »

Setting your form's ShowInTaskbar property set to false should prevent it from being shown on the taskbar.

You may find the following helpful:
https://www.sapien.com/blog/2019/01/10/ ... lications/
https://www.sapien.com/blog/2017/07/10/ ... owershell/
Brittney
SAPIEN Technologies, Inc.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Systray icon: click to open form?

Post by stevens »

Created a sample form in att..
-It works fine but "hide in taskbar" still shows a minimized window in left corner.
-2 icons or show at startup ...
-I'd like to set extra menuitem which says "disable/enable at startup" but default it should start at windows startup. How can I do this?
Thanks!

-Update
I keep on getting errors uploading the zip file, so I post hereby the OneDrive location
https://1drv.ms/u/s!AuBjpW9I3NC4mt1fTNq ... Q?e=O2xr0q
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Systray icon: click to open form?

Post by brittneyr »

[Topic moved to PowerShell GUIs forum by moderator]
Brittney
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Systray icon: click to open form?

Post by brittneyr »

From your script, you have created a context menu includes the "disable/enable at startup", but you have not set it with your NotifyIcon object or manually open it anywhere.

I recommend trying to hide the form rather than minimize.
Brittney
SAPIEN Technologies, Inc.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked