Monodevelop: Porting with C # / Visual Studio: double click disappears

Over the past 2 months, I have written an application in C # in Visual Studio. Now I need to port this application to Linux on Monodevelop. Well, I already solved most of the porting errors, but there is one that I cannot understand. All the double-click and mouse events from Visual Studio stopped working - I even created a small application of 1 form, which I ported to Mono with only one form and one event (double-click) - it also did not work - so this means that Monodevelop can can port double click events from Visual Studio? I already checked the WND_Proc function, and Linux does not throw any corresponding double-click event (it was 515 for the window and 3 hundreds in the title bar ...). I already refuse to prepare and prepare to write additional code to fix all the double-click problems in my code, but maybe someone has an answer.

I use Ubuntu linux (if necessary, I can check the kernel version), MONO: 2.8.3, Visual Studio 2008 and the project in .NET 3.5.

+4
source share
2 answers

When using mouse clicks, there are two main differences between Windows and Gtk # that you should keep in mind:

  • Gtk # does not offer double-click signals ("Events" in Windows lingo), but only single 'click' signals. However, the Gdk library implements both double-click and triple-click with its EventButton class!
  • Gtk # distinguishes between Widgets (or "Controls" on Windows lingo) and "Containers" (no direct mapping on Windows). Most widgets hosted on the Gtk # form will NOT receive mouse click events. To receive a mouse event, you need to place the widget inside a specific container, such as an EventBox.

This is how you do Gtk #:

a. Add an EventBox to the form (in the example below: eventbox1). You can place it behind other widgets or, because it does not appear, unless you specifically select it (or change its background color). You can place the widget inside the EventBox, but you are limited to only one widget, which will also receive the shape and size of the EventBox.

C. Add a ButtonPressEvent signal from the Common Widget Signals signals to this EventBox (in the following example: OnEventbox1ButtonPressEvent)

Each time the mouse button (on the left, in the middle or in the center or combination) is called inside the EventBox, it calls this event, and the OnEventbox1ButtonPressEvent () function will be called. If you need to identify the button that was pressed when processing this event, use the uint value in: args.Event.Button usually "1" will be the left mouse button, "2" the center button and "3" the right button ('2' can be also by pressing the left and right buttons).

By the way, mouse movement events (without clicking a button) are not sent by default. Therefore, if you need to feel them, you will need to add PointMotionMask, as well as in the first code example below.

Here is a sample ButtonPress event handler code (EventBox name is "eventbox1") that captures a double-click event using the EventButton class:

// 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 only if this is a double-click event } 

The order of the received events (in the case of a double click):

  • Gdk.EventType.ButtonPress
  • Gdk.EventType.ButtonRelease
  • Gdk.EventType.ButtonPress
  • Gdk.EventType.TwoButtonPress
  • Gdk.EventType.ButtonRelease

Hope this helps!

+2
source

GTK # deals with double-click events other than Windows Forms. You will need to write code to translate events. If you do this, you can also spend time arguing against double-clicking as idioms.

0
source

Source: https://habr.com/ru/post/1432814/


All Articles