2

I'm using GTK# on monodevelop 3.0.4.6, on windows, I got a Gtk.EventBox connected to a ButtonPressEventHandler detecting single click (EventType.ButtonPress), but the double click (EventType.TwoButtonPress) is NEVER triggered, does anyone has any idea why? I even tried adding the "[GLib.ConnectBefore]" attribute on my handler method, but it didn't change anything. I tried with a TreeView, a Button & an EventBox, all those where detecting single click, but none double...


Sample of my code :

// Somewhere in the constructor :
eventBox.ButtonPressEvent += new ButtonPressEventHandler(myButtonPressHandler);


// The called method
private void myButtonPressHandler(object obj, Gtk.ButtonPressEventArgs a)
{
    EventButton ev = a.Event;
    // single click
    if (ev.Type == EventType.ButtonPress)
    {
        MyLogger.output("1");
    }
    // double click
    else if (ev.Type == EventType.TwoButtonPress)
    {
        MyLogger.output("2");
    }
}
Vinay
  • 6,891
  • 4
  • 32
  • 50
user1675393
  • 21
  • 1
  • 2

2 Answers2

4

Your code example, with a slight modification, works well on my machine. I created an EventBox names 'eventbox1' and captured the signal 'ButtonPressEvent'. The only difference is the way I checked if the event received is a double-click. I also made sure that double click events are sent (see the first line) but in my case it wasn't really needed, it worked anyway.

Here is the code that works on my machine and captures the double-click:

// The following line is may not be needed but is here to show how to do it
eventbox1.GdkWindow.Events = eventbox1.GdkWindow.Events | Gdk.EventMask.ButtonPressMask;

protected void OnEventbox1ButtonPressEvent (object o, ButtonPressEventArgs args)
{
    if( ((Gdk.EventButton)args.Event).Type == Gdk.EventType.TwoButtonPress)
        System.Media.SystemSounds.Beep.Play (); // Play a sound if this is double-click
}

Come to think of it, if you still don't receive the double click event on your system, could it be that your system is set to ignore double clicks?

OM55
  • 1,038
  • 8
  • 10
  • I tried your code instead of mine, and it didn't work better (I just used `eventbox1.Events` and not `eventbox1.GdkWindow.Events`). It also catches single click. I'm using windows 7 and I didn't manually disable double click (and I open folders with double click without any problem), so I don't see why would it differ. My current idea is about a bad use of it (or a bug) in Windows only, and hope for an easy fix (of my code)... I don't wanna code my own implementation of double click! – user1675393 Sep 17 '12 at 17:39
  • Has no one any idea how to fix this?! – user1675393 Sep 23 '12 at 17:02
  • I think (but am not sure) that you have to use eventbox1.GdkWindow.Events since only Window events are exposed. Also you need to make sure that the EventBox member variable 'VisibleWindow' is set to 'true' or otherwise no events will be caught. I didn't know you are working under Windows (I checked it in Ubuntu) but I just checked and my code above works just the same in Windows. Can you please post a complete code that DOESN'T work on your machine, and I can test it on mine, both Windows and Linux? – OM55 Sep 23 '12 at 20:13
  • Hello again, I prepared for you 2 complete identical monodevelop projects showing capturing single, double and triple click (on any of the mouse buttons). One projects is for Monodevelop Windows and can be downloaded from: http://db.tt/qUKOU60c and the other project is for Monodevelop Linux and can be dwonloaded from: http://db.tt/CTVbNoy8 I'll try also to post the complete source in a separate reply. Hope that helps, please let me know how is went, I'm curious... – OM55 Sep 23 '12 at 20:29
  • Thank you for your time MO55, really. But unfortunately, I don't detect double or triple click on your project (with squares) neither. – user1675393 Sep 25 '12 at 19:29
  • Here is a test I have done if you wanna try : https://www.dropbox.com/s/y4jca09qks5efkc/ClickTest.rar – user1675393 Sep 25 '12 at 20:27
  • I tried the 'ClickTest' project you included, and it works just fine on my machine -as is, without making any changes at all! Both 'Click' and 'DoubleClick' are recognized and the correct message is displayed. – OM55 Sep 27 '12 at 20:01
  • So it HAS to be something on your settings of Mono, gtk or the related libraries. If you want to give it a try, I prepared for you ready for download the mono/gtk/.NET libraries for Windows. ALL three are needed: gtk-sharp-2.12.10.win32 (http://db.tt/3ewCXxWV), mono-2.10.8-gtksharp-2.12.11-win32-1 (http://db.tt/E0ViyBiR), winsdk_web (http://db.tt/4I2NjsTO) – OM55 Sep 27 '12 at 20:11
  • I already had the same gtk-sharp-2.12.10.win32 and mono-2.10.8-gtksharp-2.12.11-win32-1 installed, however I had the version V7.0A of the winsdk_web and not the V7.1... And that installation failed, I'll try to reinstall it later. – user1675393 Sep 27 '12 at 21:56
  • Another thing you can do to narrow down on the problem, is to run another mono program that uses double-click. If the double click on that one doesn't work either - we will know the problem is with the mono or Gtk# libraries or their settings (environment variables and such. Check your environment variables!). If the double-click works fine - .... then I'm out of options... If the 'exe' included in my projects is not working for you as is, while is working on my computer, there is obviously no problem with Monodevelop... – OM55 Sep 28 '12 at 18:53
  • When I tested your project, I recompiled the .exe and launched it from monodevelop, same for my test application... I just tried it without monodevelop and the doubleclick is catched for both applications!!! I'll open a bug on monodevelop! Thank you! – user1675393 Sep 29 '12 at 09:33
  • You are welcome! Maybe you should try first to upgrade to the latest version of Monodevelop. – OM55 Sep 29 '12 at 16:43
0

This is a known bug in the version of GTK+ included with Mono. If you run your app with the .NET runtime on Windows, it'll work fine, as GTK# for .NET bundles a different version of GTK+.

Mikayla Hutchinson
  • 16,113
  • 2
  • 44
  • 50