systray application

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 4 years 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
JMGodin
Posts: 4
Last visit: Thu Jun 10, 2021 6:23 am

systray application

Post by JMGodin »

Hello,

I would like to create a systray application with powershell studio.
I don't see method that I have to use.

I already tried to use a notifyicon object in my Form.
But
when I do $Form.hide or $Form.visible=$false, my form exit.
when I do $Form.WindowState = 'Minimized' and $Form.ShowInTaskbar = $false, my form exit.

So
I bought PowerShell Studio 2019 to be able to create "windows Tray App"
But when I create a Tray App, I don't see how to use my notification icon to hide or show my form.
_ Maybe I have to use $SAPIENHost. ? But I found nothing about this new variable.
_ Is there some click events that I could use ? Like with notifyicon object in a form.

Regards,
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: systray application

Post by Alexander Riedel »

Alexander Riedel
SAPIEN Technologies, Inc.
JMGodin
Posts: 4
Last visit: Thu Jun 10, 2021 6:23 am

Re: systray application

Post by JMGodin »

Thank you, but I already read them.
That why I know that $SAPIENHost object exist.
I found nothing about this new object. (any method to explore it ?)

I don't want to click on a menu, but just on the icon.
Like it's possible to do with the $notifyicon object.

If I build with $notifyicon, I can't hide the aplication
If I build with "Windows Tray App", I'm unable to handle the event MouseClick in the systray icon
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: systray application

Post by jvierra »

Please post a simple version of your PSF file.

The icon has an event that is raised when it is clicked. You will need to use that event and not themenu events.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: systray application

Post by jvierra »

The first example test code does not work as it is missing files and was built to only run on the 2017 version of PSS.

The second linked example suffers from most of the same deficiencies.

The URL file should not be stored in "Programs" and the icon file needs to be in the app folder.

Change this: "C:\projects\2019 Products and versions\PrimalScript 2019\x64\Debug\ScriptPackage.ico" to point to an icon.

Change the URL file to the app folder or to a user folder under AppData\Local
JMGodin
Posts: 4
Last visit: Thu Jun 10, 2021 6:23 am

Re: systray application

Post by JMGodin »

Thank you for your answer, but I don't understand what I can copy/past for you ?
I'm asking "how to make a systray application".

MainForm.psf :
  1. $form1_Load={
  2.     $textbox1.Text = "Hello " $env:USERNAME
  3. }
1th example :
I don't want to show a popoup.
I want to show a form. (my form will be more complex than just say "hello")

2nd example :
I don't want a menu on the systray icon.
I just want to click on the icon, to show my form,
AND be able to close the form and still have the systray icon, to be able to show my form again.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: systray application

Post by jvierra »

You will have to create a custom systray application that does what you want. The Sapien Systray host does not allow us to add an event to the icon. We can only add menu items.

Here is a simple example of how to create an icon form that can respond to the click on the icon. The form is semi-transparent and can be fully hidden in code. The click can unhide the form or launch a new form.

It is the most basic example that I have and has no fancy gadgets. You can use it as a start. Build it with the forms host.
Attachments
Demo-IconNotify.psf
(16.9 KiB) Downloaded 191 times
JMGodin
Posts: 4
Last visit: Thu Jun 10, 2021 6:23 am

Re: systray application

Post by JMGodin »

Ok. So I have to forget the Sapien Systray.

If I understood, the method would be :
Build a MainForm with 0% Opacity, with a notifyicon, just to stay in memory.
And this notifyicon can show/hide a ChildForm where all my app is.

If that work, that answer all I wanted :)
Thank you ! ;)


My app have to be installed on 5000 workstations, 24/7.
Does this transparent MainForm could disturb my users ?
_ With 0px * 0px size, the MainForm still be a bit big, and could bother some click.
_ Less important, stay in "Alt+Tab" view.

Maybe I have to change language to do it ?
But I need a lot of PowerShell commands in my app.
Any suggestion ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: systray application

Post by jvierra »

I would have the icon just start an exe. Now the two are decoupled making the design simpler.
This topic is 4 years 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