[Gtk-sharp-list] How to Use TextTag

Thomas Weiser gtk-sharp-list at thomasweiser.de
Mon May 26 08:05:16 EDT 2008


Hello Marc,

to apply formatting to portions of a text buffer you can use a TextTag 
like this:

	TextView textView = new TextView ();
	TextBuffer buffer = textView .Buffer;
	buffer .Text = "abcdefghijk";

	TextTag tagBold  = new TextTag ("bold");
	tagBold .Weight = Pango .Weight .Bold;
	buffer .TagTable .Add (tagBold);

	TextIter iter1 = buffer .GetIterAtOffset (3);
	TextIter iter2 = buffer .GetIterAtOffset (6);
	buffer .ApplyTag (tagBold, iter1, iter2);

You can find a longer example in the GtkDemo application that comes with 
GTK#. The relevant source file is also here:

http://code.google.com/p/slickr-dotnet/source/browse/trunk/SlickrGtk/DemoTextView.cs?r=2

And there is a good tutorial for TextView here (it's written for the 
C-version of GTK+):

http://www.bravegnu.org/gtktext/

Regards
Thomas Weiser


Marc Glenn schrieb:
> Hello guys,
> 
>      I am creating an application that uses Gtk.TextView.
>      My problem is how can I format the text in the TextView like 
> setting to bold, adjusting font-size, foreground color.
> 
>      Is this possible with TextTag? Do you know any sample code on how 
> to use this?
>      Thanks in advance.
> 
> Regards,
> Marc Glenn
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 



More information about the Gtk-sharp-list mailing list