简体   繁体   English

如何在c#GTK mono中将背景色设置为固定?

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

I am new to C# Gtk in mono. 我是C#Gtk的新手。 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. 默认情况下, Gtk.Fixed没有自己的Gdk.Window但是在其父窗口上绘制,并且不绘制任何背景。 To have it draw a background, just tell it to create its own Gdk.Window : 要使其具有背景,只需告诉它创建自己的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) 

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

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