简体   繁体   中英

Mono GTK# Text View - how to get user input?

I am trying to write a rather simple note-taking app for Elementary OS. It is my first time in C#/Mono world. I encoutered this problem.

Is it possible to take input from a Text View? I know how to do it from Entry... but how to get it from Text View?

As opposed to the simpler Entry class for rather short texts, TextView class is structured in a way so the data is stored in a separate data model object. That data model, a text buffer, is accessible by means of the Buffer property .

The TextBuffer.Text property of that object allows you to retrieve or modify the text shown in the TextView . Refer to the example in the TextView docs to see its exemplary use.

StreamWriter sw = new StreamWriter("Test.txt");
sw.Write(textview3.Buffer.Text); //Write textview1 text to file
//textview3.Buffer.Text = "Saved to file !"; //Notify user
sw.Close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM