简体   繁体   English

如何在 gtk 中设置 window 标题栏#

[英]How to set window title bar in gtk#

I have a problem, I want to use the header bar as the titlebar in gtk#, but here is the error that was created:我有一个问题,我想使用 header 栏作为 gtk# 中的标题栏,但这是创建的错误:

error CS1061: 'Window' does not contain a definition for 'gtk_window_set_titlebar' and no accessible extension method 'gtk_window_set_titlebar' accepting a first argument of type 'Window' could be found (are you missing a using directive or an assembly reference?)错误 CS1061:“Window”不包含“gtk_window_set_titlebar”的定义,并且找不到接受“Window”类型的第一个参数的可访问扩展方法“gtk_window_set_titlebar”(您是否缺少 using 指令或程序集引用?)

This is the gtk# that I used: GTK#这是我使用的 gtk#: GTK#

And here is my code:这是我的代码:

namespace gtkapp
{
    class MainWindow : Window
    {
        private int _counter = 0;
        static private int _max = 1000;


        [UI] private Label _label1 = null;
        [UI] private Label _label2 = null;
        [UI] private Button _button1 = null;
        [UI] private Button _button2 = null;
        [UI] private LevelBar lb = new LevelBar(0, _max);
        [UI] private HeaderBar _headerbar = null;
        [UI] private Window MainWindoww = null;

        public MainWindow() : this(new Builder("MainWindow.glade")) { }

        private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow"))
        {
            builder.Autoconnect(this);
            MainWindoww.gtk_window_set_titlebar(MainWindoww, _headerbar);
            DeleteEvent += Window_DeleteEvent;
            _button1.Clicked += Button1_Clicked;
            _button2.Clicked += Button2_Clicked;

            _headerbar.Title = "GTK clicker";

            Decorated = false;

            lb.Value = 0;
            lb.MaxValue = 1000000;
        }

        private void Window_DeleteEvent(object sender, DeleteEventArgs a)
        {
            Application.Quit();
        }

        private void Button1_Clicked(object sender, EventArgs a)
        {
            _counter++;
            // _counter += 100;
            lb.Value += 10;
            lb.MaxValue += 1;
            if(lb.Value < _max)
            {
                _label1.Text = "This GTK button has been clicked " + _counter + " time(s).";
            }
            else if(lb.Value >= _max)
            {
                _label1.Text = "This GTK button has been clicked for the " + _counter + " time(s).";
            }
        }

        private void Button2_Clicked(object sender, EventArgs a)
        {
            Application.Quit();
        }
    }
}

Something equivalent of gtk_window_set_titlebar()相当于gtk_window_set_titlebar()

Solution that I found from a comment.我从评论中找到的解决方案。

use this.Titlebar = (the variable of the header bar, my variable name is _headerbar); Decotated = false;

The order must be above or it will not work订单必须在上面,否则将不起作用

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

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