简体   繁体   中英

How to set background color to fixed in c# GTK mono?

I am new to C# Gtk in mono. I have made a window with two buttons with this code :

using Gtk;
using Gdk;

class FirstScreen : Gtk.Window
{

public FirstScreen() : base("Buttons")
{
    SetDefaultSize(250, 200);
    SetPosition(WindowPosition.Center);

    DeleteEvent += delegate { Application.Quit(); };

    Fixed fix = new Fixed();

    Button btn1 = new Button("Take Photo");

    Button btn2 = new Button("Take Video");

    Gdk.Color col = new Gdk.Color();
    Gdk.Color.Parse("red", ref col);
    fix.(StateType.Normal, col);

    fix.Put(btn1,30, 80);
    fix.Put(btn2, 130, 80);


    Add(fix);
    ShowAll();
}


public static void Main() 
{
    Application.Init();
    new FirstScreen();
    Application.Run();
}

}

I Want the Background color of the window or the fixed to be changed .How could we do that Please help?

By default Gtk.Fixed doesn't have its own Gdk.Window but draws on its parent window and doesn't draw any background. To have it draw a background, just tell it to create its own Gdk.Window :

fix.HasWindow = true;

That's all.

You would try use eventbox. And establish your object in box. For example:

eventbox.ModifyBg (StateType.Normal, new Gdk.Color (0, 0, 0));  //Zeros represent of (r,g,b) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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