Menu Button Behavior

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 7 years and 1 month 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Menu Button Behavior

Post by jvierra »

Not enough information. What context menus?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Menu Button Behavior

Post by jvierra »

Yes - within a container the calculations are wrong. We need to calculate the position relative to the group box then translate to the screen.

Here is an example.
Attachments
Test-MenuB.psf
(30.44 KiB) Downloaded 116 times
User avatar
njcappa
Posts: 66
Last visit: Tue Jan 26, 2021 6:59 am

Re: Menu Button Behavior

Post by njcappa »

Do I need to open a request/ticket elsewhere for this to be escalated for a fix?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Menu Button Behavior

Post by jvierra »

You can fix it yourself. Just make a new control set with the fixes.

I will post to Alex or Devon to have them look at this thread. Changing it may take some time. We willl have to let them decide. I am not a Sapien employee. THe people in this forum are all just community members.
User avatar
njcappa
Posts: 66
Last visit: Tue Jan 26, 2021 6:59 am

Re: Menu Button Behavior

Post by njcappa »

Re-creating the control set does not fix it. The issue remains.

Please let them know that.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Menu Button Behavior

Post by jvierra »

No. You have to create a new control set based on the old control set but with updated code. See the documentation on how to create custom control sets to learn how to do this.

Custom control sets are a feature of PSS that let use modify controls or define new control groups with code. The sets in PSS are mostly demos of what can be done or are just conveniences that Sapien has built over the years. They are fully modifiable. I currently have a number that are updates based on the original Sapien control.

This is how I patched the position.
  1. $menuButton2_Click={
  2.     #Show the menu
  3.     $point = New-Object System.Drawing.Point ($groupbox2.Location.X, $groupbox2.Bottom)
  4.     $menuButtonContextmenustrip2.Show($form1.PointToScreen($point));
  5. }
You can change this to get the parent container on button initialization so that it always uses the containers position as the anchor.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Menu Button Behavior

Post by jvierra »

Here is the generic solution that will work in all versions of the control.
  1. $menuButton3_Click={
  2.     #Show the menu
  3.     $x = $this.Parent.Location.X + $this.Location.X + 10
  4.     $y = $this.Parent.Location.Y + $this.Location.Y + 10
  5.     $point = New-Object System.Drawing.Point ($x, $y)
  6.     $menuButtonContextmenustrip3.Show($this.FindForm().PointToScreen($point));
  7. }
User avatar
njcappa
Posts: 66
Last visit: Tue Jan 26, 2021 6:59 am

Re: Menu Button Behavior

Post by njcappa »

Makes sense - I set the drawing point to the value I needed and it worked just fine.

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

Re: Menu Button Behavior

Post by jvierra »

I had a bit of time to look at the best way to do this. If the control set uses the following line all will be well.

$menuButtonContextmenustrip1.Show($this.Parent.PointToScreen($point))
This topic is 7 years and 1 month 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