Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Theme and dynamically added control #107

Closed
ThibaudMZN opened this issue Aug 31, 2020 · 10 comments
Closed

Dark Theme and dynamically added control #107

ThibaudMZN opened this issue Aug 31, 2020 · 10 comments

Comments

@ThibaudMZN
Copy link

Hi,
I'm running into a strange and really specific issue with the dark theme.

When creating a custom control with a panel, and adding it in designer mode into a Form, everything works fine with dark mode. But if I had it by script, then it seems like the MaterialSkinManager cannot access the custom control background and leave it white.

This is how I had the custom control :

CustomControl customControl = new CustomControl(); flowLayoutPanel.Controls.Add(customControl);

You can see below a picture illustrating this behavior, on the left the custom control added from designer mode, and on the right the one added by script.

Any idea on why this is happening would be appreciated, maybe I need to force the background manually ?

Thanks !

Capture

@leocb
Copy link
Owner

leocb commented Aug 31, 2020

Hi, you must change the background color on code or enable "enforce back color" as in this wiki entry https://github.com/leocb/MaterialSkin/wiki/FAQ#backcolor-property-on-non-material-components
You can also check how the designer creates the code and copy that

@ThibaudMZN
Copy link
Author

ThibaudMZN commented Aug 31, 2020

Hey, both of those solutions are not working, the "EnforceBackColor" is already set to true, and copying the designer code doesn't work either. I suspect this is a bug due to the order in which the controls are colored and added ?
Any way, I can still force the backColor from code but it seems to me like its's a bug :)

@leocb
Copy link
Owner

leocb commented Aug 31, 2020

The flow layout may be breaking something, could you try adding the panel directly to the form?

@ThibaudMZN
Copy link
Author

I tried with a tabControl and also by adding it directly to the form, and still have the same behavior !

@leocb
Copy link
Owner

leocb commented Aug 31, 2020

Weird, are you overriding the onPaint function on your control?
Could you try doing the same with q simple panel? (not a custom control)

@ThibaudMZN
Copy link
Author

ThibaudMZN commented Aug 31, 2020

I'm not overriding the onPaint function no, and it doesn't work with a simple panel !

@ThibaudMZN
Copy link
Author

I manage to solve this issue by calling the AddFormToManage function or setting the theme after dynamically adding the control, since those functions calls the private UpdateBackgrounds function.

Though, this is not ideal because in the case of a desktop App i'm working on, controls are added after all of the form management function are called.

May I suggest adding a public function to MaterialSkinManager to be able to force the background on a newly added control ? I can work on this and make a PR if you think that's the best approach !

@ThibaudMZN
Copy link
Author

ThibaudMZN commented Aug 31, 2020

Maybe the best option would be to add a public function to MaterialSkinManager to set the background color on a specific control, and then add an event listener on the MaterialForm itself to check for ControlAdded and apply the correct Background on it !
(This bug actually comes from the fact that the controls background are set only when changing the Theme or adding the form to be managed, and if any controls are added later they are not modified)

@leocb
Copy link
Owner

leocb commented Aug 31, 2020

Thanks for the fix!

@leocb leocb closed this as completed Aug 31, 2020
@ThibaudMZN
Copy link
Author

No problem !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants