简体   繁体   English

GTK# 应用程序结构

[英]GTK# sctructure of application

I am newbie in desktop application programs and I want to create an applications which will use only 1 window for all things.我是桌面应用程序的新手,我想创建一个只使用 1 个窗口的应用程序。 First of all I create a simple LOGIN form with "Login" button and 2 text fields.首先,我创建了一个带有“登录”按钮和 2 个文本字段的简单登录表单。 When user successfully logins window changes it's form.当用户成功登录时,窗口会改变它的形式。 I pinned a picture of the, lets say, MAIN form, where user can switch between "screens" (I don't know how to properly name it) by clicking 1..4 buttons at the right.我固定了一张主窗体的图片,用户可以通过单击右侧的 1..4 按钮在“屏幕”(我不知道如何正确命名)之间切换。 And we have the top panel with profile photo and nickname which persist all the time program still in the MAIN form.我们有带有个人资料照片和昵称的顶部面板,它们一直保留在主窗体中的程序中。

So, the main question is: HOW should I do it?所以,主要问题是:我应该怎么做? Which widgets I should use and how does dynamic content in GTK+ (and others, like Qt etc.) should be implemented?我应该使用哪些小部件以及应该如何实现 GTK+(以及其他,如 Qt 等)中的动态内容? So I want answers, links to topics which covers this situation, guides and lessons.所以我想要答案、涵盖这种情况的主题链接、指南和课程。 Anything will help.任何事情都会有所帮助。

I read a lot of documentation but it seems that I can't find proper information just because I don't know how to formulate my problem for search query.我阅读了很多文档,但似乎我无法找到正确的信息,因为我不知道如何为搜索查询制定我的问题。

Thank you, I hope I'll find some help.谢谢,我希望我能找到一些帮助。

PS I am gonna use C# and GTK# for this application. PS 我将在这个应用程序中使用 C# 和 GTK#。

You only need to create various boxes ( Gtk.VBox or Gtk.HBox ), and hide/show them as you need to.您只需要创建各种框( Gtk.VBoxGtk.HBox ),并根据需要隐藏/显示它们。 I did not know about Gtk.Stack, but I bet it uses the same principle, maybe with some optimization.我不知道 Gtk.Stack,但我敢打赌它使用相同的原理,也许做了一些优化。

class UniqueWindowView: Gtk.Window
{
    void Build()
    {
        var vbMainBox = new Gtk.VBox();

        this.vbLoginPage = this.BuildLoginPage();
        this.vbNotebook = this.BuildNotebook();

        vbMainBox.PackStart( this.vbLoginPage, true, true, 100 );
        vbMainBox.PackStart( this.vbNotebook, true, true, 5 );
        vbMainBox.Show();

        this.Add( vbMainBox );
        this.SetSizeRequest( 600, 400 );
        this.Show();
    }

    // ...

    public Gtk.VBox vbLoginPage {
        get; private set;
    }

    public Gtk.VBox vbNotebook {
        get; private set;
    }

    public Gtk.Notebook nbNotebook {
        get; private set;
    }

    public Gtk.Button btLogin {
        get; private set;
    }
}

Once you have this scheme running, you have to prepare to show or hide the appropriate boxes.运行此方案后,您必须准备显示或隐藏相应的框。

class UniqueWindowCtrl
{
    public UniqueWindowCtrl()
    {
        this.view = new UniqueWindowView();
        this.view.DeleteEvent += (o, args) => this.Quit();
        this.view.btLogin.Clicked += (sender, e) => this.ShowNotebook();
    }

    public void Start()
    {
        this.ShowLogin();
    }

    public void ShowLogin()
    {
        this.view.vbLoginPage.Show();
        this.view.nbNotebook.Hide();
    }

    public void ShowNotebook()
    {
        this.view.vbLoginPage.Hide();
        this.view.nbNotebook.Show();
    }

    void Quit()
    {
        this.view.Hide();
        Gtk.Application.Quit();
    }

    UniqueWindowView view;
}

You can find the whole source code for a unique window in GTK# here .您可以在此处找到GTK# 中唯一窗口的完整源代码。 Hope this helps.希望这可以帮助。

I suggest you take a look at GtkStack .我建议你看看GtkStack This will enable you to have multiple widget layouts in a single window and provides you with an easy way to change which widgets are shown.这将使您能够在单个窗口中拥有多个小部件布局,并为您提供一种更改显示的小部件的简单方法。 GtkStack is commonly used with StackSwitcher . GtkStack 通常与StackSwitcher一起 使用 However normal buttons will work just as well.然而,普通按钮也能正常工作。 Can I also suggest you use Glade to lay out your widgets?我还可以建议您使用Glade来布置您的小部件吗? This will give you a presentation of how your widgets sets will look.这将向您展示您的小部件集的外观。

Edit: GtkStack does not appear to be available for Gtk#.编辑:GtkStack 似乎不适用于 Gtk#。

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

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