我想要处理System.Windows.Forms.NotifyIcon的BalloonTipClicked。也就是说,当提示被单击时,我想处理事件。我的代码如下,但是我不能捕获事件。请帮帮我!
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Timers")
## This is the location of your download files
$notification = "E:\TDdownload"
$notification = New-Object System.Windows.Forms.NotifyIcon
$notification.Icon = "C:\Users\Sefler\Desktop\PerfCenterCpl.ico"
$notification.BalloonTipIcon = "Info"
$notification.BalloonTipText = "Windows will now try to clean "+ $fileLocation +" as scheduled."
$notification.BalloonTipTitle = "Windows auto maintaince"
$notification.Visible = $True
$notification.ShowBalloonTip(15000)
## Register a click event
register-objectevent $notification BalloonTipClicked -sourceIdentifier notification_event
## Wait for the onClick event
wait-event -timeout 15 发布于 2010-01-22 23:14:13
好了,我现在和你在一起了。这在ISE内部工作:
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Timers")
## This is the location of your download files
$notification = "E:\TDdownload"
$notification = New-Object System.Windows.Forms.NotifyIcon
$notification.Icon = "C:\Users\Sefler\Desktop\PerfCenterCpl.ico"
$notification.BalloonTipTitle = "Windows auto maintaince"
$notification.BalloonTipIcon = "Info"
$title = "Windows will now try to clean {0} as scheduled." -f $fileLocation
$notification.BalloonTipText = $title
$notification.Visible = $True
## Clear any previous events
Remove-Event notification_event -ea SilentlyContinue
## Register a click event
register-objectevent $notification BalloonTipClicked notification_event
$notification.ShowBalloonTip(15000)
## Wait for the onClick event
wait-event -timeout 15 -sourceIdentifier notification_event > $null
Remove-Event notification_event -ea SilentlyContinue
"Done!!"
Unregister-Event -SourceIdentifier notification_event注意:当您在窗口主体中单击时,这是有效的,但当您单击"x“关闭窗口时,则不起作用。因此,您可能还希望订阅BalloonTipClosed事件(或者不订阅BalloonTipClicked)。
https://stackoverflow.com/questions/2118093
复制相似问题