如何在程序启动时正确恢复Gtk窗口大小?
我正在使用 GTK# GUI 框架用 C# 编写应用程序,以使其跨平台。 许多事情是在 GTK# 中完成的,与 WPF/Windows.Forms 中不同,但其中大部分我都能自己解决。
有一个“小”问题,当我试图解决它时,它变得不那么“小”。 当应用程序关闭时,我将窗口位置和最大化标志保存到配置文件中。 但是当我尝试恢复窗口参数时,它们没有正确恢复。
我尝试使用的方法:
SetSizeRequest():
this.SetSizeRequest((int)config["windowwidth"], (int)config["windowheight"]);
SetDefaultSize():
this.SetDefaultSize((int)config["windowwidth"], (int)config["windowheight"]);
Resize():
this.Resize((int)config["windowwidth"], (int)config["windowheight"]);
问题是: 其中一些方法根本不起作用(什么也不改变)。其他人的行为很奇怪:将窗口大小设置为不是从配置中加载的窗口大小,使窗口不断扩展等。
我还添加了对一个特定小部件的大小的限制:
Gdk.Geometry geom = new Gdk.Geometry();
geom.MinWidth = 800;
geom.MinHeight = 400;
this.SetGeometryHints(BoxNotebook, geom, Gdk.WindowHints.MinSize);
当我将所有这些一起使用时,它变得一团糟。 在程序启动时恢复窗口大小的正确方法是什么?
I am writing application in C# using GTK# GUI framework to make it cross-platform.
Many things are being done in GTK# not like in WPF/Windows.Forms, but most of them I was able to solve on my own.
There is a "little" problem, what became not that "little" when I tried to solve it.
I am saving window position and maximized flag to config file when application is being closed.
But when I am trying to restore window parameters, they are being restored not correctly.
Methods I tried to use:
SetSizeRequest():
this.SetSizeRequest((int)config["windowwidth"], (int)config["windowheight"]);
SetDefaultSize():
this.SetDefaultSize((int)config["windowwidth"], (int)config["windowheight"]);
Resize():
this.Resize((int)config["windowwidth"], (int)config["windowheight"]);
The problem is:
Some of these methods does not work at all (change nothing). Others behave strangely: set window size to not the one was loaded from config, make window continuously expanding, etc.
I am also adding a constraint on size of one specific widget:
Gdk.Geometry geom = new Gdk.Geometry();
geom.MinWidth = 800;
geom.MinHeight = 400;
this.SetGeometryHints(BoxNotebook, geom, Gdk.WindowHints.MinSize);
When I use all this together, it is becoming a complete mess.
What is the correct way to restore window size at program startup ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Resize
适用于我的应用程序。您确定从配置文件加载了正确的值吗?编辑
这是一个 Glade 文件,似乎可以满足您的要求:
Resize
works in my application. Are you sure that the correct values are being loaded from the config file?EDIT
Here is a Glade file that seems to do what you want: