简体   繁体   English

GTK C#Widget更改颜色不起作用

[英]GTK C# Widget Change Color Not working

Im trying to change the color of button widget in GTK# by using 我试图通过使用改变GTK#中按钮小部件的颜色

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? 为什么是这样?

Instead of the 'flaky' ModifyBase, you can just use the ModifyBG method, same params are passed. 您可以使用ModifyBG方法,而不是“片状”ModifyBase,传递相同的参数。

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. 顺便说一下,因为你在Mono GTK#下处理GTK2.x所以我说是片状的,而且当涉及到'主题'和Mono时,双方都有很多问题。 GTK3 has a consist model using a CSS approach, but the Mono distro is stuck on GTK2. GTK3有一个​​使用CSS方法的编组模型,但Mono发行版卡在GTK2上。 You can search for theming GTK 2.x if you wish to theme/colorize your application the GTK way. 如果您希望以GTK方式主题/着色您的应用程序,您可以搜索主题GTK 2.x. 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). 注意:如果使用MonoDevelop / XS,请确保在IDE之外定期测试/运行它,因为应用程序主题将发生变化(这在OS-X上非常明显,而且这个问题可以追溯到多年和几年)。

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. 您可以在Mono电子邮件主题中搜索此条件,因为它自2007年以来一直存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM