GTK C# Widget Change Color Not working

2019-05-12 01:44发布

问题:

Im trying to change the color of button widget in GTK# by using

button1.ModifyBase(Statetype.Normal,new Gdk.Color(1,1,1));

This is called from another button click event,but the widget color is not updated

why is this?

回答1:

Instead of the 'flaky' ModifyBase, you can just use the ModifyBG method, same params are passed.

button1.ModifyBG(Statetype.Normal,new Gdk.Color(1,1,1));

BTW, I say flaky since you are dealing with GTK2.x under Mono GTK# and there are tons of issues on both sides when it comes to 'theming' and Mono. GTK3 has a consist model using a CSS approach, but the Mono distro is stuck on GTK2. You can search for theming GTK 2.x if you wish to theme/colorize your application the GTK way. Note: If using MonoDevelop/XS, make sure you routinely test/run it outside of the IDE as the app theming will change (this is really apparent on OS-X and again, an issue that goes back years and years).

If you have other widgets that do not 'behave' correctly in their background colors, you can place them within an eventbox widget as that widget has a background while others might not. You can search for this condition within the Mono email threads as it has been around since 2007.



标签: c# mono gtk gtk#