Adding dynamically ToolstripMenuItems

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
KelvionITI
Posts: 1
Last visit: Wed Mar 27, 2024 12:38 am

Adding dynamically ToolstripMenuItems

Post by KelvionITI »

Hi,
is there a way to build dynamically a Menustructure via Powershell Studio?
I want to add a menu called tools and add there sub menuitems which should open a RDP session to a server.
This should be dynamic.

Tools
- RDP Serverxyz
- RDP Server XXZ
- RDP Server YYZ

I get the Hostnames from a Powershell query.


Thanks
Regards
Andreas
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding dynamically ToolstripMenuItems

Post by jvierra »

Yes- You can create menu items and add them to the menu using code, I suggest searching for examples. There are many available.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Adding dynamically ToolstripMenuItems

Post by jvierra »

The following code adds an item to a menu strip dropdown
  1. #
  2.         $item1ToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem
  3.     $item1ToolStripMenuItem.Name = 'item1ToolStripMenuItem'
  4.     $item1ToolStripMenuItem.Size = '152, 24'
  5.     $item1ToolStripMenuItem.Text = 'Item 1'
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked