contextmenu submenu click

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 2 years and 2 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
paddy75
Posts: 27
Last visit: Sat Mar 16, 2024 11:11 pm

contextmenu submenu click

Post by paddy75 »

Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.199
OS: Windows 10 Pro (64 Bit)
Build: v10.0.19043.0


Hello,

I have a contextmenu with a submenu which is filled dynamically by a xml-file. How can I add a click event for a dynamic build submenu?
2022-01-22 17_52_43-Window.jpg
2022-01-22 17_52_43-Window.jpg (13.55 KiB) Viewed 3341 times
The parent entry "Lang" is created in with the designer.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: contextmenu submenu click

Post by jvierra »

The following article will tell you how to use a context menu.

https://info.sapien.com/index.php/guis/ ... ip-control
paddy75
Posts: 27
Last visit: Sat Mar 16, 2024 11:11 pm

Re: contextmenu submenu click

Post by paddy75 »

jvierra wrote: Sat Jan 22, 2022 12:06 pm The following article will tell you how to use a context menu.

https://info.sapien.com/index.php/guis/ ... ip-control
yes, i know this article and read it.
I tried the example from this, it's only applied to the main entry "Lang".

But I have no idea how to add an event for the submenu. What do I miss here or I don't understand all of this.

I using contextmenu in other forms too, but here I created it completly with the designer and had no problems :cry:
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: contextmenu submenu click

Post by jvierra »

The article explains that in detail. It also has a cod example. You will have to carefully follow the article and it is normal to copy the steps in a form and try each element until you understand how the control works.
Important Events:
ItemClicked
This event occurs when a menu item is clicked. Use this event as a general catch all event for the menu items. It allows you to react to the menu item clicks without having to set each individual menu item’s click event.

You can access the clicked item by accessing the event’s argument ClickItem property:

$_.ClickedItem
It is critical to learn how to read technical documentation when working with high technology systems like computers. If you are just an end user then you can get away with some guess work but to write code, then learning the technology from the documentation is required although there are classes that can be taken that will get you started.

Here is an excellent free beginner's book that covers basic PowerShell with a small amount of info on how to use PowerShell with WinForms.

https://www.sapien.com/books_training/W ... werShell-4
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: contextmenu submenu click

Post by Lembasts »

paddy75 wrote: Sat Jan 22, 2022 1:21 pm
jvierra wrote: Sat Jan 22, 2022 12:06 pm The following article will tell you how to use a context menu.

https://info.sapien.com/index.php/guis/ ... ip-control
yes, i know this article and read it.
I tried the example from this, it's only applied to the main entry "Lang".

But I have no idea how to add an event for the submenu. What do I miss here or I don't understand all of this.

I using contextmenu in other forms too, but here I created it completly with the designer and had no problems :cry:
In the link you'll find the following which addresses your issue I believe:

"This event occurs when a menu item is clicked. Use this event as a general catch all event for the menu items. It allows you to react to the menu item clicks without having to set each individual menu item’s click event.
You can access the clicked item by accessing the event’s argument ClickItem property:
$_.ClickedItem"
This topic is 2 years and 2 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