Create Themes?

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.
User avatar
JohnTitor
Posts: 153
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Fri Nov 17, 2017 8:49 pm

Create Themes?

Post by JohnTitor »

How can I give my users the choice of themes that can be saved and loaded on next application launch?

jvierra
Posts: 14335
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Create Themes?

Post by jvierra »

There is no support for pluggable themes in Windows Forms. You can do this with ASPX and WPF.

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Create Themes?

Post by JohnTitor »

I've read somewhere about clixml?

jvierra
Posts: 14335
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Create Themes?

Post by jvierra »

That has nothing to do with forms.

help export-clixml -online

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Create Themes?

Post by JohnTitor »

So back again.. After seeing a few posts around I've came to the conclusion this is the best way I've found to do it

Create a new Registry Key, name it Colors, create Keys under there with your themes..
RegEdit.png
RegEdit.png (24.68 KiB) Viewed 1262 times
Then apply them using a button click
Themes.psf
(275.04 KiB) Downloaded 44 times
Notice the Set-Theme string is blank, that's how I find what theme the user last left off with.

Is there a way to do this differently?

jvierra
Posts: 14335
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Create Themes?

Post by jvierra »

Load the whole key and assign the colors based on property name.

You should not create app specific keys at the root of the registry. Create an app key in the correct place and structure it correctly. This will allow each app to have a specific key for its settings.

It would be even better to use a CliXml file as this is easier to load and manage.

You mistake is in calling what you are doing a theme. WinForms does not support themes. WPF supports full theming. What you are doing is just assigning properties. This can also be more easily managed using data binding. All control properties support data binding so the assignment and saving is automated.

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Create Themes?

Post by JohnTitor »

Are there examples on how to do these things?

jvierra
Posts: 14335
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Create Themes?

Post by jvierra »

There are many but you will have to search. Most are in C#.

jvierra
Posts: 14335
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Create Themes?

Post by jvierra »

If you only have a few simple control settings to change this can be a best method for automating settings. It can also be applied without using any variables because it telss you where the control is by name and what settings to override. The settings can be applied by looping through the hierarchy.

Code: Select all

<Form name="myform1">
    <Property name="BackColor">LightGray</Property>
    <Label name="label1">
        <Property name="Color">Blue</Property>
        <Property name="BackColor">Red</Property>
        <Property name="Font">
            <FontFamily>Microsoft Sans Serif</FontFamily>
            <emSize>24.0</emSize>
            <Style>Italic</Style>
        </Property>
    </Label>
</Form>
This allows an easy way to edit the settings and a way to apply them. Apply defaults from the script home folder then apply custom settings from the user profile parallel settings folder.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Create Themes?

Post by davidc »

Just wanted to let you guys know I'm working on something for the next service release ;-)
David
SAPIEN Technologies, Inc.

Locked