PowerShell Studio 2012: What’s New? (Part 2)

Last time we looked at PowerShell Studio’s new UI features such as the updated Ribbon and custom layouts. Now we will take a look at the new Forms Designer features.

Styles

Have you ever got tired of applying the same properties over and over to controls such as anchoring? Well this is where Styles come into play, one of the new additions to PowerShell Studio’s Designer.

So what is a Style?

Styles are a set of predefined properties that you can quickly assign to one or more controls within the designer.

Applying Styles:

Let’s look at some sample Styles and how you apply them. You start by opening the designer and selecting the control(s) you wish to apply a Style to.

Select Controls

Next you can access the Style List by using:

The Designer Context Menu:

Apply Style Context Menu

Or the Ribbon:

Apply Style Ribbon

The quickest method is to use the keyboard shortcut: Ctrl + L

 

Next you will be presented with a list of Styles you can apply to the selected control(s).

Select Style Dialog

 

Some Styles only apply to a specific control type. You can check the “Show styles for same type only” checkbox to only display control specific styles.

Filtered Styles

(If a Style only applies to a specific type, the type will be displayed in blue.)

 

The following are example uses for styles:

The Console Font Style changes the control’s font to a fixed sized font. This style is useful for displaying PowerShell output in a TextBox.

Console Font Style

Before applying Style:

Text Before Style

After applying Style:

Text After Style

 

Use the OK Button Style to convert any button into a OK button.

Apply OK Button Style

Before applying Style:

Button Before Style

After applying Style:

Button After Style

The Button’s text is changed to “OK” and the DialogResult property is also changed to ‘OK’ , which triggers the form to close when the button is pressed (See: Spotlight on the Button Control blog article).

 

Creating New Styles:

Now, not only can you use preexisting Styles but you can also create your own custom Styles.

To create a new Style you must first select the control you wish to use as a template.

In this case, I want to create a Style that applies a blue color to text.

Blue Button

In this example, we will use the button control as a base.

Next select the Create Style option (Ctrl + Shift + L):

Create Style Option

 

You will be presented with the “Create Style Template” dialog:

Create Style Template Dialog

The dialog displays the selected source control (only one source control per style).

Next you can choose to limit the Style to a ‘Matching Type’ or to apply it to ‘Any Type’.

Choose Style Limitation

In this case, we want to apply this style to ‘Any Type’. If you chose the ‘Matching Type’ options, the style could only have been applied to Buttons.

Next enter creator information and the mandatory description of the Style:

Style Description

After entering the description, you must check all the properties of the template control you would like the Style to incorporate.

Select Properties for Style

In this case, we only want the ForeColor, which is set to blue beforehand on the button.

Next press the ‘Create’ button and save the new Style:

Save the Style

 

Now apply the new Style to other controls:

Applying the New Style

What’s cool is that you can apply multiple styles to multiple controls at once.

The controls after applying multiple Styles:

Controls After Applying Styles

 

Next: Part 3  – Control Sets