[Gtk-sharp-list] mouse event from a textview

Alexandros Frantzis alfius at freemail.gr
Sat Mar 18 04:45:46 EST 2006


On Tue, 2006-03-14 at 20:03 -0500, David Cantin wrote:
> Hi, 
> 
> I'm not able to receive any event when I click inside a textview and I
> did not found any example on the web to show me how to do it. 
> 
> In fact, what I want is to be aware of movement of the cursor produced
> by the mouse inside the textview.
> 
> I have joined a simple application to this message to show one of my
> attempt.
> 
> So, if you have any clues, please, let me know
> 
> thanks
> 
> David

One way to achieve what you want is to create your own TextView-derived
class:

public class MyTextView : TextView
{
    public MyTextView() { }

    protected override bool OnButtonPressEvent(Gdk.EventButton e)
    {
        // call base (original) handler
	base.OnButtonPressEvent(e);
        
        // do custom stuff
        Console.WriteLine("event from the textview");
        
        // return that the event was handled
        return true;
    }
}

Then create and use a MyTextView widget instead of the one created by
glade (remember to remove the TextView from the glade file):

...
TextView myTextView=new MyTextView();
win.Add(myTextView);
win.ShowAll();
...

HTH,
Alexandros



More information about the Gtk-sharp-list mailing list