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.
Locked
JMGodin
Posts: 4
Joined: Tue Apr 30, 2019 11:04 am

systray application

Post by JMGodin » Thu May 16, 2019 5:44 am

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: 7023
Joined: Tue May 29, 2007 4:43 pm

Re: systray application

Post by Alexander Riedel » Thu May 16, 2019 6:03 am

Alexander Riedel
SAPIEN Technologies, Inc.

JMGodin
Posts: 4
Joined: Tue Apr 30, 2019 11:04 am

Re: systray application

Post by JMGodin » Mon May 20, 2019 2:58 am

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

User avatar
jvierra
Posts: 13733
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: systray application

Post by jvierra » Mon May 20, 2019 12:03 pm

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.

User avatar
jvierra
Posts: 13733
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: systray application

Post by jvierra » Mon May 20, 2019 12:18 pm

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
Joined: Tue Apr 30, 2019 11:04 am

Re: systray application

Post by JMGodin » Wed May 22, 2019 2:04 am

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 :

Code: Select all

$form1_Load={
$textbox1.Text = "Hello " $env:USERNAME
}
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.

User avatar
jvierra
Posts: 13733
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: systray application

Post by jvierra » Wed May 22, 2019 6:34 am

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 21 times

JMGodin
Posts: 4
Joined: Tue Apr 30, 2019 11:04 am

Re: systray application

Post by JMGodin » Thu May 23, 2019 6:52 am

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 ?

User avatar
jvierra
Posts: 13733
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: systray application

Post by jvierra » Thu May 23, 2019 7:31 am

I would have the icon just start an exe. Now the two are decoupled making the design simpler.

Locked