Reputation: 13
I want to convert this to Powershell but I'm not quite sure how to. The important part is creating a handler for the trayMenu item.
NotifyIcon trayIcon;
ContextMenuStrip trayMenu;
trayMenu = new ContextMenuStrip();
trayMenu.Items.Add("Login", ContextMenuStripItemImages).Click += new EventHandler(Login_Click); //Create a new item in the context menu strip and link its Click event with Login_Click
trayIcon = new NotifyIcon();
trayIcon.ContextMenuStrip = trayMenu; //Set the ContextMenuStrip of trayIcon to trayMenu
}
private void Login_Click(object sender, EventArgs e)
{
//Do something when Login is clicked
}
Thanks in advance for any help!
Upvotes: 1
Views: 1035
Reputation: 202022
Like so:
trayMenu.Items.Add("Login", ContextMenuStripItemImages).add_Click({... script here ...})
Sender is represented with $this
and e (EventArgs) by $_
.
Upvotes: 1