【问题标题】:How to set background color to fixed in c# GTK mono?如何在 c# GTK mono 中将背景颜色设置为固定?
【发布时间】:2013-08-28 15:32:58
【问题描述】:

我是单声道 C# Gtk 的新手。我用这段代码制作了一个带有两个按钮的窗口:

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();
}

}

我想改变窗口的背景颜色或固定的颜色。我们该怎么做?请帮忙?

【问题讨论】:

    标签: c# gtk monodevelop


    【解决方案1】:

    默认情况下Gtk.Fixed 没有自己的Gdk.Window,但在其父窗口上绘制并且不绘制任何背景。要让它绘制背景,只需告诉它创建自己的Gdk.Window

    fix.HasWindow = true;
    

    就是这样。

    【讨论】:

    • 嗨@fog 我有一个大问题。你有 GTK 单声道的经验你能帮我聊天吗?
    • @NavdeepSinghBedi 确定。
    • 我有一个项目在 c# Gtk# 中使用网络摄像头你能帮忙吗?
    • @NavdeepSinghBedi 是的,但你为什么不在 stackoverlow 上问一下?
    • 我已经浪费了大约一周的时间在 google 上搜索并且还在 stackoverflow 上询问了没有人回答但给出了 -ve 标记...我已经为在 windows 上运行的可视化 C# 开发了代码,但我在 Ubuntu Linux 上需要它.
    【解决方案2】:

    你会尝试使用事件框。并在框中建立您的对象。例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      • 2012-05-02
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      相关资源
      最近更新 更多