notifyicon closes the application

Ask your PowerShell-related questions, including questions on cmdlet development!
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 7 years and 6 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
Gordeev Alexaender
Posts: 10
Last visit: Tue Jan 09, 2018 1:50 am

notifyicon closes the application

Post by Gordeev Alexaender »

Hi,

If you execute the code below, the program closes.
What could be the problem? that need to be left alone notifyicon. I've tried to change $form.hide() to $form.ShowInTaskbar = $false. All the same, there are no errors.

$form_Resize={
#TODO: Place custom script here
if (Form.WindowState -eq "Minimized")
{
$form.hide()
#$Monitoring.ShowInTaskbar = $false
}
}


$notifyicon1_MouseDoubleClick=[System.Windows.Forms.MouseEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
#TODO: Place custom script here
$form.WindowState = 'Normal'
#$form.ShowInTaskbar = $true

}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: notifyicon closes the application

Post by jvierra »

Yes. That is correct. If you hide a dialog it is the same as closing it.
User avatar
Gordeev Alexaender
Posts: 10
Last visit: Tue Jan 09, 2018 1:50 am

Re: notifyicon closes the application

Post by Gordeev Alexaender »

How, then, hide the form, remove the icon from the taskbar and leave only the icon in the system tray? and expand by double-clicking on notifyicon back to the form, if necessary.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: notifyicon closes the application

Post by jvierra »

You can't with PowerShell. PowerShell uses only modal dialogs. When a dialog is hidden it is closed. When the dialog closes it will remove the notify icon and all events from the system and the script will terminate.
Here is one way to use the icon without a form: https://technet.microsoft.com/en-us/lib ... 30952.aspx
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: notifyicon closes the application

Post by DevinL »

Duplicate topic, conversation continues here: viewtopic.php?f=21&t=10661
DevinL
SAPIEN Technologies, Inc.
This topic is 7 years and 6 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