Basics: Copying Controls and Events in the Designer

The Window Forms designer in PowerShell Studio lets you cut (Ctrl+X), copy (Ctrl+C), and paste (Ctrl+V) controls within the current form as well as between other forms. When copying a control, it will retain the properties set on the control. When you run this script with this copied control, you may notice that it does not act as it does in the previous script.

This is because the events’ code associated with that control does not copy over, meaning all event code will need to be copied manually over and set if this is a new form. If this is the same form, and the same event code still applies, the event code needs to be connected to the newly copied control.

How to Subscribe a Control to an Event

All subscribed events can be seen from the Functions and Properties panels. An event can be set in the designer with the control selected from the Properties panel event tab:

Double-clicking an event listed in the Properties panel will add that event. Copying and pasting the event code from another form for that type of event can also work. If the event code already exists in the script, it should appear in the dropdown menu:

A new event can also be added by right-clicking in the designer with the control selected, or Ctrl+E:

Control Sets and Property Sets

If you find you are copying a control consistently, it might be a good idea to make a control set. It is always a good idea to make code reusable to avoid having to do/write the same bit of code over and over again. A control set groups together controls and scripts that can be used in forms like a standard control. This can be done by adding controls to a form, configuring their properties, and writing all of the code required to make your new control set function correctly. Then you would select all of the controls that are to be included in the control set and click Create Control Set (Designer->Templates) or Ctrl+T:

After creating your control set, the next time controls are loaded into the ToolBox panel, the new control will be available:

A property set is similar except it is just the property settings of a control that are saved. They can be generic, or specific, to a particular type of control. To create a property set, configure the control. Then select the control and click Create Property Set or Ctrl+Shift+L:

To browse and select property sets, click Apply Property Set or Ctrl+L:

This will open the Select Property Set dialog:

It is also important to note that Apply Property Set, Create Property Set, and Create Control Set can be accessed by right-clicking in the designer with control(s) selected:


As always, any feedback is appreciated. If you have a particular type of blog article or product feature request you would like to see, please submit your suggestions on the Wish List and Feature Requests forum or the new Feature Requests page.