Maintain visual style for button

Ask your PowerShell-related questions, including questions on cmdlet development!
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 11 years and 7 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
StupidSexyFlanders
Posts: 107
Last visit: Thu Apr 29, 2021 8:47 am

Maintain visual style for button

Post by StupidSexyFlanders »

I need to change a button from its inherited color to something else. That's easy enough to do, but it seems to also change the default visual style (i.e. two-tone) to a single color button.

I've poked around and read a few things about resetting the UseVisualStyleBackColor property before setting the BackColor property. But the best I've been able to do so far is change the color of the button text -- the button color itself stays the same.
Mike
StupidSexyFlanders
Posts: 107
Last visit: Thu Apr 29, 2021 8:47 am

Maintain visual style for button

Post by StupidSexyFlanders »

I need to change a button from its inherited color to something else. That's easy enough to do, but it seems to also change the default visual style (i.e. two-tone) to a single color button.

I've poked around and read a few things about resetting the UseVisualStyleBackColor property before setting the BackColor property. But the best I've been able to do so far is change the color of the button text -- the button color itself stays the same.
Mike
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Maintain visual style for button

Post by jvierra »

Are you using PrimalForms or PowerShell Studio?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Maintain visual style for button

Post by jvierra »

Swet UseVisualStyleBackColor and select the color you want from the dropdown.

The colors are limited to what is in the dropdown and that will vary from system to system. ALL are cross compatible. I think Win7 has more variations but I am not sure.

StupidSexyFlanders
Posts: 107
Last visit: Thu Apr 29, 2021 8:47 am

Maintain visual style for button

Post by StupidSexyFlanders »

Yeah, I get how the color can be changed. What I can't do is change the color AND maintain the modern look-and-feel of the default. If I set UseVisualStyleBackColor to $true, set the backcolor to something, it stays grey:


If I set the FlatStyle property to Flat or PopUp the new color shows up. But then it loses the visual style:


Here the general idea of what I am hoping to achieve:
Mike
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Maintain visual style for button

Post by jvierra »

You can't have both. VisualStyle limits you to the 'chrome' and teh colors of the 'theme'. Flat and Popup do not use the chrome or them. "Flat' means flat not fancy.

You can get custom controls that will do what you are trying to do.d
StupidSexyFlanders
Posts: 107
Last visit: Thu Apr 29, 2021 8:47 am

Maintain visual style for button

Post by StupidSexyFlanders »

Excellent. That's what I needed to know. Thanks a lot!
Mike
This topic is 11 years and 7 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