Setting Properties in Panel vs. Script

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 1 year 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
Scott Rosenbloom
Posts: 14
Last visit: Thu Feb 22, 2024 7:41 am

Setting Properties in Panel vs. Script

Post by Scott Rosenbloom »

Hi,

If I've scripted the size of an object in the MainForm.psf file, in the $frmInstApps_Load event (for example, $myButton.Location.X = 15), will that override whatever setting might be entered for that property in the Properties panel? If not, how do I make sure that it does? Also, is putting that code in the MainForm.psf file > $frmInstApps_Load event the right place to put it?

Thanks,
Scott
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 1:00 pm
Answers: 39
Been upvoted: 30 times

Re: Setting Properties in Panel vs. Script

Post by brittneyr »

It should work if you are putting the code in the load event, but that is not how you resize a control. The example provided changes the location of the button rather than resizing. To resize, it would look something like the following:
  1. $myButton.Size = New-Object System.Drawing.Size(98, 33)
Setting this in the load event will override the value set from the Properties panel. As I don't know what you are attempting to accomplish, I cannot say it is the right place. Unless you are changing the value multiple times in your script, setting it once from the Properties panel is the best choice.
For better understanding how psf files generate a ps1 file, the following article may be helpful:
https://www.sapien.com/blog/2022/01/04/ ... ll-studio/
Brittney
SAPIEN Technologies, Inc.
Scott Rosenbloom
Posts: 14
Last visit: Thu Feb 22, 2024 7:41 am

Re: Setting Properties in Panel vs. Script

Post by Scott Rosenbloom »

Sorry, yes, I meant to type $myButton.Size, not $myButton.Location.X.

To be clear, if I wanted to set the left padding for that button, could I enter $myButton.Padding.Left = 15 ?

Scott
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 1:00 pm
Answers: 39
Been upvoted: 30 times

Re: Setting Properties in Panel vs. Script

Post by brittneyr »

Padding is a little different. You need to provide a value for all sides like so:
  1. $myButton.Padding = '0, 15, 0, 0'
This would be generated for you if you used the Properties panel rather than attempting to set it under the form load event.
Brittney
SAPIEN Technologies, Inc.
Scott Rosenbloom
Posts: 14
Last visit: Thu Feb 22, 2024 7:41 am

Re: Setting Properties in Panel vs. Script

Post by Scott Rosenbloom »

OK, so is it possible to set, for example, just the Y location value of an element? If so, how would you do that?
Thanks
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 1:00 pm
Answers: 39
Been upvoted: 30 times

Re: Setting Properties in Panel vs. Script

Post by brittneyr »

[Topic was moved to PowerShell GUIs forum by moderator]
Brittney
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 1:00 pm
Answers: 39
Been upvoted: 30 times

Re: Setting Properties in Panel vs. Script

Post by brittneyr »

I recommend setting values in the Properties panel then exporting the script to ps1 to give you an idea of how they are written.
SPS_PropertiesPanelLocation.png
SPS_PropertiesPanelLocation.png (29.05 KiB) Viewed 642 times
Brittney
SAPIEN Technologies, Inc.
This topic is 1 year 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