To create a new paned window, call one of:
Hpaned hpaned1 = new Hpaned(); Vpaned vpaned1 = new vpaned();After creating the paned window widget, you need to add child widgets to its two halves. To do this, use the functions:
hpaned1.Add1(Widget child); hpaned1.Add2(Widget child);hpaned1.Add1() adds the child widget to the left or top half of the paned window.
hpaned1.Add2() adds the child widget to the right or bottom half of the paned window.
As an example, we will create part of the user interface of an imaginary email program. A window is divided into two portions vertically, with the top portion being a list of email messages and the bottom portion the text of the email message. Most of the program is pretty straightforward. A couple of points to note: text can't be added to a Text widget until it is realized. This could be done by calling Realize(), but as a demonstration of an alternate technique, we connect a handler to the "realize" signal to add the text. Also, we need to add the Gtk.Shrink option to some of the items in the table containing the text window and its scrollbars, so that when the bottom portion is made smaller, the correct portions shrink instead of being pushed off the bottom of the window.
// paned.cs - Gtk# Tutorial example // // Author: Alvaro Ramirez // // (c) 2002 Alvaro Ramirez namespace GtkSharpTutorial { using System; using Gtk; using GtkSharp; using GLib; class PanedMain { static Gtk.ScrolledWindow CreatList() { //Declare scroll window and tree view along with all necessary //to control th tree view Gtk.ScrolledWindow ScrWindow; Gtk.TreeView MyTree; Gtk.ListStore store; Gtk.TreeIter iter; Gtk.CellRenderer cell; Gtk.TreeViewColumn column; //Create scrolled window and format it ScrWindow = new Gtk.ScrolledWindow(); ScrWindow.SetPolicy(Gtk.PolicyType.Automatic,Gtk.PolicyType.Automatic); //Create ListStore to be used in tree view store= new Gtk.ListStore((int)TypeFundamentals.TypeString); //Create treeview and format it MyTree=new TreeView(store); MyTree.HeadersVisible = true; MyTree.HeadersClickable = false; MyTree.EnableSearch = false; //Add treeview to scrolled window ScrWindow.AddWithViewport(MyTree); //Create column for treeview column = new Gtk.TreeViewColumn (); //Create cell renderer for column cell = new Gtk.CellRendererText(); //Format column column.Title = "Messages"; column.PackStart (cell, true); column.AddAttribute (cell, "text", 0); //Add column to treeview MyTree.AppendColumn (column); //populate treevie iter = new TreeIter(); for(int i = 0;i<10;i++) { GLib.Value value = new Value("Message "+i.ToString()); store.Append(out iter); store.SetValue(iter,0,value); } return ScrWindow; } static Gtk.ScrolledWindow CreateText() { //Declare scroll window and TextView along with all necessary //to control the TextView Gtk.ScrolledWindow ScrWindow; Gtk.TextView TextArea; Gtk.TextBuffer buffer; //Create scrolled window and format it ScrWindow = new Gtk.ScrolledWindow(null,null); ScrWindow.SetPolicy(Gtk.PolicyType.Automatic,Gtk.PolicyType.Automatic); //Create text buffer use to store text in textview buffer=new Gtk.TextBuffer(new Gtk.TextTagTable ()); //Set buffer text buffer.Text="From: JustLinux Forums Mailer >webmaster@justlinux.com< \n"+ "To: alramire@syr.edu \n"+ "Subject: Reply to post Screen Shots......Just Because \n"+ "Date: Fri, 18 Apr 2003 19:43:16 GMT \n" + "Hello tucolino, \n"+ "\n"+ "hecresper has just replied to a thread you have subscribed to entitled " + "- Screen Shots.... \n"; //Create textview TextArea=new Gtk.TextView(); //Add previous text buffer to textview TextArea.Buffer=buffer; //format textview TextArea.Editable=false; TextArea.CursorVisible=false; TextArea.WrapMode=Gtk.WrapMode.Word; //Add textview to scrolled window ScrWindow.AddWithViewport(TextArea); TextArea.ShowAll(); ScrWindow.ShowAll(); return ScrWindow; } static public int Main (string[] args) { Application.Init (); Window window = new Window ("Paned Window"); window.DeleteEvent += new DeleteEventHandler (delete_event); //Format main window window.BorderWidth=10; window.WidthRequest=450; window.HeightRequest=400; window.Resizable=true; window.SetPosition(Gtk.WindowPosition.Center); //create VPaned widget (vertical) VPaned vpaned1 = new VPaned(); //vpaned1.Add1(CreatList()); //vpaned1.Add2(CreateText()); //Add top and bottom widgets. Last two arguments are resize and shrink (bool) vpaned1.Pack1(CreatList(),true,true); vpaned1.Pack2(CreateText(),true,true); window.Add (vpaned1); window.ShowAll(); Application.Run (); return 0; } static void delete_event (object obj, DeleteEventArgs args) { Application.Quit (); } static void QuitApp (object obj, EventArgs args) { Application.Quit (); } } }