GTK C# Widget Change Color Not working

时光怂恿深爱的人放手 提交于 2019-12-10 10:28:16

问题


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.



来源:https://stackoverflow.com/questions/20585582/gtk-c-sharp-widget-change-color-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!