GTK#窗口未完全呈现 [英] GTK# window not rendered completely

查看:104
本文介绍了GTK#窗口未完全呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在尝试在Debian(Raspbian)系统上使用Mono和GTK#开发程序.

我面临的问题是,完全随机绘制的GUI(由Stetic设计师或其动态元素生成)没有完全绘制,缺少了Label元素或整个小部件中的一些字符,主要是那些是动态创建的.这是它在对话框窗口上的外观: http://imgur.com/oEZRg7c (文本被截断)

一旦一个窗口出现此问题,其他所有窗口都会出现相同的问题,有时会丢失整个小部件,即使这些小部件是在以后创建的也是如此.解决方案通常是退出程序并重新打开它,因为它只是随机发生的.

这是我大多数窗口的构造函数的样子(Build()之后的部分有所不同):

public partial class ErrorSolutionDialog : Gtk.Dialog
{
    public ErrorSolutionDialog (string errorMessage, string solutionHint)
    {
        this.WidthRequest = this.Screen.Width;
        this.HeightRequest = this.Screen.Height;
        this.Maximize ();
        this.Fullscreen ();
        this.KeepAbove = true;
        this.DestroyWithParent = false;
        Build ();

        this.ErrorMessage.Markup = "<b><span size='xx-large'>" + errorMessage + "</span></b>";
        this.SolutionHint.Text = solutionHint;
    }
}

解决方案

我不会说在Xamarin Studio/Monodevelop中使用Stetic设计器是不好的,但是作为任何软件,它肯定都存在一些问题. /p>

此外,在任何软件环境中使用任何设计器,将永远使您与该开发平台联系在一起.最后,除了对您来说完全陌生之外,创建的源代码将几乎无法维护.

这就是为什么我总是建议摆脱设计师的原因.您可以按照 Gtk#教程(如本教程)进行操作,您会发现它很简单而且很有意义.而且,您将完全掌控您的代码.

关于Gtk#的基础知识是使用VBoxes和HBoxes创建布局.例如,以下代码创建一个布局,其中的对话框中将具有TreeView和TextView.

var swWin1 = new Gtk.ScrollWindow();
var swWin2 = new Gtk.ScrollWindow();

// TextView
this.txtView = new Gtk.TextView();
swWin1.AddWithViewport( this.txtView );

// TreeView
this.tvView = new Gtk.TreeView();
swWin2.AddWithViewport( this.tvView );

// Layout
var hBox = new HBox( false, 2 );
hBox.PackStart( swWin1, true, true, 5 );
hBox.PackStart( swWin2, true, true, 5 );
this.VBox.PackStart( hBox, true, true, 5 );

PackStart()是一种神奇的方法,用于将小部件添加到布局中.布尔值告诉Gtk扩展小部件. ScrollWindow 滚动条添加到任何小部件.

最后,我的建议是执行任何操作,请使用 Gtk.Action ,并在其中调用其方法 CreateMenuItem() CreateToolItem()为了创建菜单项和工具栏按钮,而不是一次又一次地重复相同的代码.

希望这会有所帮助.

Right now, I am trying to develop a program using Mono and GTK# on a Debian (Raspbian) system.

The issue I'm facing is, that, completely randomly, the GUI (generated by the Stetic designer or its dynamic elements) isn't completely drawn, missing either a few characters from a Label-element or whole widgets, mostly those that were dynamically created. This is how it looks on a dialog window: http://imgur.com/oEZRg7c (text is cut off)

As soon as one window shows this issue, every other window has the same issues, sometimes missing whole widgets, even if those were created afterwards. The solution is usually to quit the program and reopen it, as it only randomly occurs.

This is how the constructor of most of my windows looks like (the part after Build() varies):

public partial class ErrorSolutionDialog : Gtk.Dialog
{
    public ErrorSolutionDialog (string errorMessage, string solutionHint)
    {
        this.WidthRequest = this.Screen.Width;
        this.HeightRequest = this.Screen.Height;
        this.Maximize ();
        this.Fullscreen ();
        this.KeepAbove = true;
        this.DestroyWithParent = false;
        Build ();

        this.ErrorMessage.Markup = "<b><span size='xx-large'>" + errorMessage + "</span></b>";
        this.SolutionHint.Text = solutionHint;
    }
}

解决方案

I wouldn't say that the use of the Stetic designer inside Xamarin Studio/Monodevelop is bad, but as any piece of software it certainly has some issues.

Also, the use of any designer in any software environment will tie you to that development platform forever. Finally, the created source code will be hardly maintainable, apart from completely foreign for you.

That's why I always recommend to get rid of the designer. You can follow a Gtk# tutorial such as this one, and you'll find it is easy and rewarding. And you'll have whole and thorough control of your code.

The basics about Gtk# is creating a layout with VBoxes and HBoxes. For example, the following code creates a layout in which you'll have a TreeView and a TextView in a Dialog.

var swWin1 = new Gtk.ScrollWindow();
var swWin2 = new Gtk.ScrollWindow();

// TextView
this.txtView = new Gtk.TextView();
swWin1.AddWithViewport( this.txtView );

// TreeView
this.tvView = new Gtk.TreeView();
swWin2.AddWithViewport( this.tvView );

// Layout
var hBox = new HBox( false, 2 );
hBox.PackStart( swWin1, true, true, 5 );
hBox.PackStart( swWin2, true, true, 5 );
this.VBox.PackStart( hBox, true, true, 5 );

PackStart() is the method doing the magic in order to add a widget to a layout. The booleans tell Gtk to expand the widget. A ScrollWindow adds scrollbars to any widget.

Finally, my advice is for any action, use Gtk.Action, and call its methods CreateMenuItem() and CreateToolItem() in order to create menu entries and toobar buttons, instead of repeating the same code again and again.

Hope this helps.

这篇关于GTK#窗口未完全呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆