27.01.2024 18:42 Gtk3

Робота з TextView
Добавлення TextView в VBox з можливість прокрутки текстуusing Gtk;
void CreateFieldView(VBox vBox)
{
HBox hBox = new HBox();
vBox.PackStart(hBox, false, false, 5);
TextView fieldTextView = new TextView() { WrapMode = WrapMode.Word };
ScrolledWindow scrollTextView = new ScrolledWindow()
{
ShadowType = ShadowType.In,
WidthRequest = 100,
HeightRequest = 100
};
scrollTextView.SetPolicy(PolicyType.Automatic, PolicyType.Automatic);
scrollTextView.Add(fieldTextView);
hBox.PackStart(scrollTextView, false, false, 5);
}using Gtk;
void SetText()
{
textView.Buffer.Text = "Text";
}
string GetText()
{
return textView.Buffer.Text;
}using Gtk;
void EscapeHtml(TextView textView)
{
if (textView.Buffer.GetSelectionBounds(out TextIter start, out TextIter end))
{
//Отримати виділений текст
string selectedText = textView.Buffer.GetText(start, end, true);
//Видалення виділеного тексту
textView.Buffer.DeleteInteractive(ref start, ref end, true);
selectedText = selectedText.Replace("<", "<");
selectedText = selectedText.Replace(">", ">");
//Вставка модифікованого тексту
textView.Buffer.Insert(ref start, selectedText);
}
}© accounting.org.ua - 2025