6. Adding Buttons - CodeBlueG/PSForms GitHub Wiki
Buttons can be added to the main body of the form or to the footer section of the form, all using the same cmdlet - Add-FormButton. This cmdlet has the following attributes;
- formObject
- buttonText
- buttonFont
- buttonLocation
- buttonSize
- hidden
- disabled
Note: When the button is placed in the main section of the form, it is added at the same time as any other field. Adding a button to the footer section is done after the form has been sized.
formObject
This is a mandatory field
Enter the name of the form that you are creating, this is the same as the name used in the "Initialize-Form" cmdlet.
buttonText
This is a mandatory field
Enter the text that will display on the button.
buttonFont
This allows the font to be changed for individual buttons, otherwise the default font is used.
buttonLocation
Button location is used for buttons to be placed in the footer of the form and is an integer value. This is the button position where number 1 is the button on the right hand side, button 2 is placed on it's left and so on. The size of this button is defined when the form is initialised and can be changed at that time if required.
buttonSize
This is used when the button is placed in the main area of the form and is used in the same way as the sizing is used when placing a field on the form. The default value is "full".
hidden and disabled
These switches change the appearance and availability of the button when it is first shown. These settings can be changed later in a script to make the button usable.
Examples
Continuing from the previous examples, changing the second dateTimePicker to a button is done with;
$btnButton1 = Add-FormButton -formObject $TestForm -buttonSize HalfRight -buttonText "Test"
Adding two buttons to the footer is carried out with the following lines which must be added after the form has been sized;
$btnButton1 = Add-formbutton -formObject $TestForm -buttonText "Button 1" -buttonLocation 1
$btnButton2 = Add-formbutton -formObject $TestForm -buttonText "Button 2" -buttonLocation 2
Note that the buttons are numbered from right to left.