View Single Post
Old 05-15-2007   #1 (permalink)
Pav


 
 

Hide a Windows form

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

My System SpecsSystem Spec