Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the text of a GtkTextView?

Tags:

c#

gtk#

I can't understand how to load text into a GtkTexView, how is it done?

like image 667
stighy Avatar asked Nov 27 '10 15:11

stighy


1 Answers

You have to access the Buffer property that represents the buffer holding all the content that is shown by GtkTextView.

To simply load a text, you must set the Text property, like that:

textview1.Buffer.Text = "Some sample text that will be displayed."

Assuming the control you added has the name textview1.

If you want some more control on the apperance of the text, you have to use tags to mark the text. For example:

var tag = new TextTag (null);
this.textview1.Buffer.TagTable.Add (tag);
tag.Weight = Pango.Weight.Bold;
var iter = this.textview1.Buffer.GetIterAtLine (0);
this.textview1.Buffer.InsertWithTags (ref iter, "Bold text\n", tag);

This will insert a bold text in first line. A lot more is possible using the TextBuffer, look on the methods available on textview1.Buffer.

like image 118
silk Avatar answered Sep 27 '22 20:09

silk