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
Joined: Fri Nov 17, 2017 8:49 pm

Create Themes?

Post by JohnTitor » Wed Mar 20, 2019 10:53 pm

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

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

Re: Create Themes?

Post by jvierra » Thu Mar 21, 2019 4:54 am

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 » Thu Mar 21, 2019 7:17 am

I've read somewhere about clixml?

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

Re: Create Themes?

Post by jvierra » Thu Mar 21, 2019 7:25 am

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 » Tue Apr 09, 2019 3:23 pm

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 772 times
Then apply them using a button click
Themes.psf
(275.04 KiB) Downloaded 25 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: 13882
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Create Themes?

Post by jvierra » Tue Apr 09, 2019 3:54 pm

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 » Wed Apr 10, 2019 8:38 am

Are there examples on how to do these things?

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

Re: Create Themes?

Post by jvierra » Wed Apr 10, 2019 8:42 am

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

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

Re: Create Themes?

Post by jvierra » Wed Apr 10, 2019 8:54 am

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 » Wed Apr 10, 2019 1:35 pm

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

Locked