« Return to Thread: Gtk# TextView and Scrolling Text

Re: Gtk# TextView and Scrolling Text

by countcb :: Rate this Message:

Reply to Author | View in Thread

Emfor wrote:
Hi there,
I'm fighting with TextView widget. Everything is fine except that when I load text to it and move cursor in it - the coursor can go out of view (TextView doesn't scroll). I tried many examples with using TextIter and TextMark and ScrollToMark function, bu it simply doesn't work.
Can anyone please tell me what am I doing wrong?

--
Best regards,
Emfor

Hi.
You have to add your TextView to a ScrolledWindow widget and then add this ScrolledWindow to the window/dialog you want the TextView to be displayed in.

Below is a small test program which demostrates a srolling TextView.
Christopher.

------

using Gtk;
using Gdk;

namespace GtkTest
{
        class Program
        {
                public static void Main (string[] args)
                {
                        Application.Init ();
                        Gtk.Window win = new TestWindow();
                        win.ShowAll();
                        Application.Run ();
                }
        }
}

namespace GtkTest
{
        class TestWindow : Gtk.Window
        {
                public TestWindow() : base(Gtk.WindowType.Toplevel)
                {
                        this.DeleteEvent += this.OnDeleteEvent;
                        this.SetSizeRequest(800, 600);

                        ScrolledWindow scrolledWindow = new ScrolledWindow();
                        TextView yourTextView = new TextView();
                       
                        scrolledWindow.Add(yourTextView);
                        this.Add(scrolledWindow);
                }
               
                private void OnDeleteEvent(object sender, DeleteEventArgs a)
                {
                        System.Console.WriteLine("onDelete");
                        Application.Quit();
                        a.RetVal = true;
                }
                       
        }
}

 « Return to Thread: Gtk# TextView and Scrolling Text