Hello Don, Thanks for your reply !
Apparently, setting the Visible property to $false close the form as
well.
I know that my timer isn't added to my form (i don't know the correct
syntax to do it), but will it change anything to the global behavior
of the script ?
I'll try to find a way to have the script working. However, if someone
knows how to do it or has a script that does the same thing, I'll be
glad to hear the solution.
Thanks,
Pav
On May 15, 11:30 pm, "Don Jones [MVP]" <d...@sapien.com> wrote:
> So, event driven programming can be tricky.
>
> When you call ShowDialog(), you're showing the form modally, which means
> PowerShell "waits" until the form closes. Once the form closes, PowerShell
> can run again... but that that point, the *form* is no longer "running."
> Since ShowDialog() is the last line in your script, once the form is hidden,
> your script ends.
>
> You have options. I would recommend simply setting the form's Visible
> property. That'll leave your script running, but should control the visible
> appearance of the form - while leaving the form "open."
>
> You've got some other things going on. For one, you do know that your timer
> isn't being added to the form, right? Not sure if that's your intent or not.
>
> --
> Don Jones
> Windows PowerShell MVP
> Founder:www.ScriptingAnswers.com
> Co-Author: "Windows PowerShell: TFM"
>
> "Pav" <npawlac...@gmail.com> wrote in message
>
> news:1179242034.407687.323420@n59g2000hsh.googlegroups.com...
>
> > Hello,
>
> > I have a powershell app that i'd like to hide/show with a systray icon
> > menu. Unfortunately, My script quits as soon as i call the Hide()
> > method of the form.
> > I'm not really experienced in .NET windows classes, Perhaps the
> > problem doesn't involve powershell at all. If so, feel free to
> > redirect me toward the good group.
>
> > Here's the main structure of my script :
>
> > ----- cut here ------
> > $form = new-object
> > System.Windows.Forms.form
>
> > $mi = new-object System.Windows.Forms.MenuItem
> > $mi.Index = 0
> > $mi.Text = "Hide"
> > $mi.add_Click({
>
> > $form.hide()
> > })
>
> > $cm = new-object System.Windows.Forms.ContextMenu
> > $form.contextMenu = $cm
> > $form.contextMenu.MenuItems.AddRange($mi)
>
> > $form.ShowInTaskbar = $true
> > $form.set_autosize($true)
> > $form.Text = "My Form"
>
> > $ni = new-object System.Windows.Forms.NotifyIcon
> > $ni.Icon = New-object System.Drawing.Icon("icon.ico")
> > $NI.ContextMenu = $cm
> > $NI.Text = "Systray Text"
> > $NI.Visible =
> > $True;
>
> > $timer = New-Object System.Windows.Forms.Timer
> > $timer.Interval = 5000
>
> > $timer.add_Tick({
> > #...doing my treatment
> > })
>
> > $timer.Start()
>
> > $form.showdialog()
> > ----- cut here ------
>
> > Any ideas ?
> > Thanks,
>
> > Pav