Gtk.Bin Class
A container with just one child.

See Also: Bin Members

Syntax

public class Bin : Container

Remarks

A Bin widget is a Gtk.Container with just one child. It is used to create subclasses, since it provides common code needed for handling a single child Gtk.Widget.

Many GTK+ widgets are subclasses of Bin, including Gtk.Window, Gtk.Button, Gtk.Frame, Gtk.HandleBox, and Gtk.ScrolledWindow.

To place a child widget inside this container, use the standard Container.Add method.

For the widget to be useful, it should participate in size negotiation and size allocation using the events Widget.SizeAllocated and Widget.SizeRequested.

Sample follows.

C# Example

using System;
using Gtk;

//
// A simple Bin class: a simple container that adds padding.
//
class MyPadder : Bin {
	int pad = 50;
	Widget child;
	
	public MyPadder ()
	{
		// To track our child widget.
		Added += new AddedHandler (MyAdded);

		// Participate in size negotiation
		SizeRequested += new SizeRequestedHandler (OnSizeRequested);
		SizeAllocated += new SizeAllocatedHandler (OnSizeAllocated);
	}

	//
	// Invoked to query our size
	//
	void OnSizeRequested (object o, SizeRequestedArgs args)
	{
		if (child != null){
			int width = args.Requisition.Width;
			int height = args.Requisition.Height;
			
			child.GetSizeRequest (out width, out height);
			if (width == -1 || height == -1)
				width = height = 80;
			SetSizeRequest (width + pad * 2, height + pad * 2);
		} 
		
	}

	//
	// Invoked to propagate our size
	//
	void OnSizeAllocated (object o, SizeAllocatedArgs args)
	{
		if (child != null){
			Gdk.Rectangle mine = args.Allocation;
			Gdk.Rectangle his = mine;

			his.X += pad;
			his.Y += pad;
			his.Width -= pad * 2;
			his.Height -= pad * 2;
			child.SizeAllocate (his);
		}
	}

	//
	// Public property of the Padding widget
	//
	public int Pad {
		get {
			return pad;
		}

		set {
			pad = value;
			QueueResize ();
		}
	}

	void MyAdded (object o, AddedArgs args)
	{
		child = args.Widget;
	}
}

class Y {
	static void Main ()
	{
		Application.Init ();

		Window w = new Window ("Hello");
		MyPadder x = new MyPadder ();
		x.Pad = 100;
		Button b = new Button ("Hola");
		w.Add (x);
		x.Add (b);

		w.ShowAll ();
		
		Application.Run ();
	}
}
        

Requirements

Namespace: Gtk
Assembly: gtk-sharp (in gtk-sharp.dll)
Assembly Versions: 2.12.0.0