header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

NotifyIcon and Menustrip
Last Post 10 Nov 2007 06:52 PM by RosarioM. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
RosarioMUser is Offline
New Member
New Member
Posts:15
Avatar

--
09 Nov 2007 10:32 PM  
I am playing around with notifyicon and contextmenustrip and am trying to build a list of all the apps in the start menu and be able to launch them.   I am having issues with add_click where I can't get it to write the app I clicked on. I loop through the list of shortcuts and then create a new toolitem object for each one found.  All the other attributes I set are saved except for whatever I put in add_click.

Anyone have any ideas?


$applist =Get-ChildItem "c:\documents and settings\all users\start menu\" -recurse
foreach ($app in $applist) {
 $ToolItem =$app.name
 $ToolItem = New-Object System.Windows.Forms.ToolStripMenuItem
 $ToolItem.Size = New-Object System.Drawing.Size(152, 22)
 $ToolItem.Text = ($app.name -replace ".lnk","")
 ToolItem.add_click({Write-Host $app.name})
 $ContextMenuStrip1.Items.AddRange([System.Windows.Forms.ToolStripItem[]](@($ToolItem)))
}


Thanks

marco.shawUser is Offline
Co-Community Director
Basic Member
Basic Member
Posts:195
Avatar

--
10 Nov 2007 02:04 PM  
I don't have a fix (because I'm short on time to try... Just peaking in on a Saturday morning).

If I just do this:
$ToolItem = New-Object System.Windows.Forms.ToolStripMenuItem
$ToolItem|get-member

I see that there is no add_click method available, so it won't work the way you are trying to call it.
Marco

*Microsoft MVP - Windows PowerShell: http://www.microsoft.com/mvp
*PowerGadgets MVP: http://www.powergadgets.com/mvp
*Blog: http://marcoshaw.blogspot.com
RosarioMUser is Offline
New Member
New Member
Posts:15
Avatar

--
10 Nov 2007 02:55 PM  
Yes there is:

PS C:\> $toolitem = New-Object system.windows.forms.toolstripmenuitem
PS C:\> $toolitem |gm

TypeName: System.Windows.Forms.ToolStripMenuItem

Name MemberType Definition
---- ---------- ----------
add_AvailableChanged Method System.Void add_AvailableChanged(EventHandler value)
add_BackColorChanged Method System.Void add_BackColorChanged(EventHandler value)
add_CheckedChanged Method System.Void add_CheckedChanged(EventHandler value)
add_CheckStateChanged Method System.Void add_CheckStateChanged(EventHandler value)
add_Click Method System.Void add_Click(EventHandler value)

marco.shawUser is Offline
Co-Community Director
Basic Member
Basic Member
Posts:195
Avatar

--
10 Nov 2007 03:50 PM  
Sorry, I'm using the 2.0 CTP so that was hidden from the default get-member command.

1. ToolItem.add_click({Write-Host $app.name}): You're missing the leading "$".
2. I don't think you should be using Write-Host here, because you're not really trying to write back to the PowerShell console. Try simply $app.name which is just a string anyways, which I think is what you need.
Marco

*Microsoft MVP - Windows PowerShell: http://www.microsoft.com/mvp
*PowerGadgets MVP: http://www.powergadgets.com/mvp
*Blog: http://marcoshaw.blogspot.com
RosarioMUser is Offline
New Member
New Member
Posts:15
Avatar

--
10 Nov 2007 06:52 PM  
For item 1, that was a typo. I have the leading $ in my code.
For item 2, I tried without write-host and it still doesnt work.

The problem is that even though the other variables are set to each $toolitem, for some reason when I set the click event it always gets set to the last item in $applist. I think it's because it's an event and it doesnt get assigned until you click the item.

Not sure if this makes sense...

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer