GTK C#小部件更改颜色不起作用 [英] GTK C# Widget Change Color Not working

查看:71
本文介绍了GTK C#小部件更改颜色不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用

来更改GTK#中按钮小部件的颜色

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

这是从另一个按钮单击事件中调用的,但是小部件颜色未更新

这是为什么?

解决方案

您可以使用ModifyBG方法代替片状" ModifyBase,而要传递相同的参数.

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

顺便说一句,我说得不好,因为您正在处理Mono GTK#下的GTK2.x,并且在涉及主题"和Mono时双方都有大量问题. GTK3具有使用CSS方法的包含模型,但Mono发行版仍停留在GTK2上.如果希望以GTK方式对应用程序进行主题设置/上色,则可以搜索主题GTK2.x.注意:如果使用MonoDevelop/XS,请确保在IDE外部进行例行测试/运行,因为应用程序的主题将发生变化(这在OS-X上很明显,而且这个问题可以追溯到几年前).

如果您的其他窗口小部件的背景颜色不正确,则可以将其放置在事件框窗口小部件中,因为该窗口小部件具有背景,而其他窗口小部件可能没有背景.自2007年以来,您就可以在Mono电子邮件线程中搜索这种情况.

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?

解决方案

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.

这篇关于GTK C#小部件更改颜色不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆