[Gtk-sharp-list] Dynamically inserting widgets

Michael Hutchinson m.j.hutchinson at gmail.com
Sun Jun 25 09:08:22 EDT 2006


On 6/24/06, JimD <Jim at keeliegirl.dyndns.org> wrote:
> Michael Hutchinson wrote:
> > There's also the ReorderChild method, or you you could use some other
> > widget (e.g. a label) as a placeholder.
>
> What method would I use to replace the label widget with some other widget?

There's no method to do it directly, but it's not hard to write one,
e.g. (untested)

static void ReplaceWidget (Gtk.Widget old, Gtk.Widget new, Gtk.Box box)
{
    int pos = System.Array.IndexOf (box.Children, old);
    if (pos < 0)
        return;

    bool expand, fill;
    uint packing;
    Gtk.PackType packType;
    box.QueryChildPacking (old, out expand, out fill, out padding, out
packType);

    box.Remove (old);
    box.PackEnd (new);
    box.SetChildPacking (new, expand, fill, padding, packType);
    box.ReorderChild (new, pos);

    new.Show ();
    old.Destroy ();
}

Alternatively you could use a Bin-derived container (i.e. contains
only one object) as the placeholder, but that would be unnecessary
overhead.


More information about the Gtk-sharp-list mailing list