【发布时间】:2021-05-04 11:48:16
【问题描述】:
我有一个问题,我想在 gtk# 中使用标题栏作为标题栏,但这是创建的错误:
错误 CS1061:“Window”不包含“gtk_window_set_titlebar”的定义,并且找不到接受“Window”类型的第一个参数的可访问扩展方法“gtk_window_set_titlebar”(您是否缺少 using 指令或程序集引用? )
这是我使用的 gtk#:GTK#
这是我的代码:
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();
}
}
}
相当于gtk_window_set_titlebar()
【问题讨论】:
-
您的窗口没有
Titlebar属性或SetTitlebar()方法吗?试试this.Titlebar = _headerbar;或this.SetTitlebar(_headerbar); -
感谢您的帮助