3

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?

techno
  • 6,100
  • 16
  • 86
  • 192

1 Answers1

2

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.

  • Tried this too,not working.But it is working in case of GTK main window,when called from GTK Main thread.I tried calling this for the button from the main thread,still not working for widgets – techno Dec 15 '13 at 07:33
  • "Working in case of main window on main thread"? You 'can' set the window background color on the GTK+ main loop thread and 'not' a widget's background color parented to that window? –  Dec 15 '13 at 09:12
  • Assuming the widget you are using has a background (i.e.: not a label), if you place the .ModifyBG directly after the call to the generated code (Build() method) does the widget's background change? ```public MainWindow () : base (Gtk.WindowType.Toplevel) { Build (); button1.ModifyBg(Gtk.StateType.Normal,new Gdk.Color(255,0,0)); }``` –  Dec 15 '13 at 17:45