Документація

Gtk TextView - отримати виділений текст


Приклад

public string Selection
{
   get
   {
       Gtk.TextIter A;
       Gtk.TextIter B;
       if (textView.Buffer.GetSelectionBounds(out A, out B))
       {
           return textView.Buffer.GetText(A, B, true);
       }
       // return null when there is no selection
       return null;
   }
}

Закоментувати виділений текст

void AddCommentTag()
{
    Gtk.TextIter start;
    Gtk.TextIter end;

    if (Вміст.Buffer.GetSelectionBounds(out start, out end))
    {
        string selectedText = Вміст.Buffer.GetText(start, end, true);
        Вміст.Buffer.DeleteInteractive(ref start, ref end, true);

        selectedText = $"<!-- " + selectedText + " -->";

        Вміст.Buffer.Insert(ref start, selectedText);
    }
}

accounting.org.ua © 2023 рік