See Also: TextBuffer Members
The relationship between Gtk.TextBuffer and Gtk.TextView objects is not necessarily one-to-one. All views must contain a buffer, but a buffer does not have to be assigned a view, and one buffer may be used by multiple views.
In the following example, a single Gtk.TextBuffer object is shared between two Gtk.TextView widgets.
C# Example
using Gtk;
public class TextBufferExample
{
public static void Main ()
{
// Initialize GTK.
Application.Init ();
// Create a containing window.
Window window = new Window ("TextBuffer Example");
window.DeleteEvent += OnDelete;
window.SetDefaultSize (400, 300);
// Create a buffer and vertical panes for the views.
TextBuffer buffer = new TextBuffer (new TextTagTable ());
VPaned paned = new VPaned ();
// Create a text view for the buffer, make it scrollable, and
// add it to the first pane.
TextView view1 = new TextView (buffer);
ScrolledWindow scrolled_window1 = new ScrolledWindow ();
scrolled_window1.Add (view1);
paned.Add1 (scrolled_window1);
// Create a second text view for the buffer, make it scrollable,
// and add it to the second pane.
TextView view2 = new TextView (buffer);
ScrolledWindow scrolled_window2 = new ScrolledWindow ();
scrolled_window2.Add (view2);
paned.Add2 (scrolled_window2);
// Add the panes to the window and show it.
window.Add (paned);
window.ShowAll ();
// Run the application.
Application.Run ();
}
// Quit when the window is closed.
static void OnDelete (object o, DeleteEventArgs e)
{
Application.Quit ();
}
}