Changes

Jump to: navigation, search
no edit summary
== A Basic Windows PowerShell GUI ==
Once the WinForms assembly has been loaded the next step is to create a simple example. As previously discussed, WinForms GUIs consist of containers, controls and events. With this in mind, the following example creates a form (container) and a button (control), add adds the button to the form and displays the dialog:
<pre>
== Windows PowerShell and WinForms Events ==
The next area to cover involves the handling of events. An event is typically triggered when a user interacts with a control. For example, clicking on a button control will trigger an event. Event handlers are nothing more than lines of code which define what is to happen when the event is triggered (for example, an event handler may be written to exit the application when a ''Close'' button is clicked).
In Windows PowerShell, event handlers take the form of ''scriptblocks'', which are essentially sequences of commands wrapped in braces ({}).
== Setting WinForms Properties ==
WinForms components are essentially objects, and as such, have properties which can be set to the components alter component appearance and behavior. As with other object properties, these can be accessed using standard dot notation. In the previous example, we used this approach to set the text of the button control:
<pre>
== Bringing it all Together ==
Now that we have seen a simple GUI created in Windows PowerShell and covered some of the basic techniques we can create a slightly more complex GUI. The following script creates a GUI containing a label, button and text field. An event handler is configured on the button such that when it is clicked the text is extracted from the text field and used to construct a message which is then displayed on the label control. Note the creation of Drawing.Point objects to configure the size and location of controls on the form:
<pre>

Navigation menu