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.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Create Themes?

Post by apowershelluser »

How can I give my users the choice of themes that can be saved and loaded on next application launch?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Create Themes?

Post by apowershelluser »

I've read somewhere about clixml?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Create Themes?

Post by jvierra »

That has nothing to do with forms.

help export-clixml -online
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Create Themes?

Post by apowershelluser »

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 2947 times
Then apply them using a button click
Themes.psf
(275.04 KiB) Downloaded 117 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Create Themes?

Post by apowershelluser »

Are there examples on how to do these things?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Create Themes?

Post by jvierra »

There are many but you will have to search. Most are in C#.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

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.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked