FW: [Gtk-sharp-list] Background Coloring: Tables, HBoxes, VBoxes

Graham Oneale graham at resonline.com.au
Tue Mar 21 17:59:54 EST 2006

-----Original Message-----
From: Graham Oneale 
Sent: Wednesday, 22 March 2006 8:59 AM
To: 'Michael Hutchinson'
Subject: RE: [Gtk-sharp-list] Background Coloring: Tables, HBoxes,

Hi Michael,

Thanks for the quick response.  This works perfectly when setting the bg
color of the window, however if you attempt to do a myTable.modifyBg()
it fails.  Or a box container of any sort.

Any ideas what items I can apply styles to?

-----Original Message-----
From: Michael Hutchinson [mailto:m.j.hutchinson at gmail.com] 
Sent: Wednesday, 22 March 2006 4:03 AM
To: Graham Oneale
Cc: gtk-sharp-list at lists.ximian.com
Subject: Re: [Gtk-sharp-list] Background Coloring: Tables, HBoxes,

On 3/21/06, Graham Oneale <graham at resonline.com.au> wrote:
> Is it possible to set a background color on any of these widgets?
> I have an application in which certain container objects will require
> background color and foreground color.

http://ometer.com/gtk-colors.html has some useful info.

It can sometimes be tricky to determine where a widget is getting its
colour choice from, whether it's using Fg, Base, or Bg, and which
state it's using.

It's made harder when some widgets simply defer to the background of
the widgets behind them. Tthis is the case with containers' borders.
Try the following code:

using System;
using Gtk;

class WindowTester {
     static void Main ()
          Application.Init ();
          Window window = new Window ("This is a window");
          window.DeleteEvent += delegate {Application.Quit ();};
          window.SetDefaultSize (200, 200);

          Table tab = new Table (2, 2, true);
          window.Add (tab);
          tab.BorderWidth = 10;

          tab.Attach (new Button ("One"), 0, 1, 0, 1);
          tab.Attach (new Button ("Two"), 0, 1, 1, 2);
          tab.Attach (new Button ("Three"), 1, 2, 0, 2);

          window.ModifyBg (StateType.Normal, new Gdk.Color(255, 0, 0));

          window.ShowAll ();
          Application.Run ();

Hope this helps,

Michael Hutchinson

More information about the Gtk-sharp-list mailing list