开发者

How do you create a custom GTK# Widget with its own controls?

I am trying to create a custom GTK Widget by subclassing Gtk.Bin. I am not usin开发者_StackOverflowg the Stetic GUI builder. This widget will contain several standard Gtk widgets (VBoxs, Labels, Buttons, etc).

public class MyWidget : Gtk.Bin
{
    public MyWidget : base ()
    {
        build ();
    }
    private void build ()
    {
        VBox vbox1 = new Vbox (true, 0);
        vbox1.PackStart (new Label ("MyWidget"), true, true, 0);
        this.Add (vbox1);
    }
}

Meanwhile when I add my custom widget to the main window, I don't see anything. The windows other controls show up, space is allocated for this custom widget. I expect to see the label "MyWidget" in its space, but nothing shows up. I step thru the code in the debugger and it all gets called but its a no show at runtime.

Any help would be appreciated.


need to override:

    protected override void OnSizeAllocated (Gdk.Rectangle allocation)
    {
        if (this.Child != null)
        {
            this.Child.Allocation = allocation;
        }
    }

    protected override void OnSizeRequested (ref Requisition requisition)
    {
        if (this.Child != null)
        {
            requisition = this.Child.SizeRequest ();
        }
    }


Or probably more likely, ShowAll () as the last line in the build method after all children are packed in, unless you don't want some of them to be visible by default.


Gtk+ controls are (frustratingly) not visible by default.

Try calling .Show () on your Label.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜