Mouse events are events that refer to events of visible control elements (components) associated with the mouse. This means that you can only use the mouse object in connection with an event that refers to such mouse events:
The above instruction to display the value of Mouse.X in a console therefore produces the error message: No mouse event data. Understandable, because the procedure Form_Open() has nothing to do with the mouse.
The following section of the source code is correct:
In this way, the system determines internally in Gambas components and complex control elements such as a drawing area and other containers which (logical) sub-element of the container was clicked on. Mouse. X is compared with the absolute position of the container plus the relative position of the sub-element to its container, and the overview of events in a class captures all events related to the mouse - even if this is not immediately apparent from the name of some events:
The events of the last line are listed here and described in detail in other chapters (→ chapter 14.2.3 MouseWheel).
These procedures show you how to use selected events - MouseWheel, MouseDown, MouseUp and MouseMove - for 3 different components:
Public Sub dwgKS1_MouseWheel() If Mouse.Delta = +1 Then ' Mouse wheel forward? Enlarge picture (free definition) If fZoom < 300 Then fZoom = fZoom + 5 KS_RP_G_Drawing() ' Drawing of coordinate system, grid and graph of the function Endif Else If fZoom > 20 Then fZoom = fZoom - 5 KS_RP_G_Drawing() Endif Endif ' Mouse.Delta = +1 ? End
The 'Control_MouseWheel()' event exists for selected components. This event is triggered when the mouse wheel is moved or pressed while the mouse cursor is over the component. The event returns the value Mouse.Delta of type Float. The value is +1 if the mouse wheel has been turned forwards.
As an alternative to IF Mouse.Delta = +1 THEN… you can also use IF Mouse.Forward THEN… as an alternative to IF Mouse.
PUBLIC SUB Form_MouseDown() IF Mouse.Left THEN iDeltaX = Mouse.X iDeltaY = Mouse.Y ENDIF ' Mouse.Left ? END ' Form_MouseDown() Public Sub btnGetInformation_MouseUp() Timer1.Stop End ' btnGetInformation_MouseUp() PUBLIC SUB Form_MouseMove() IF Mouse.Left THEN FMain.Move(FMain.X - iDeltaX + Mouse.X, FMain.Y - iDeltaY + Mouse.Y) ENDIF ' Left mouse button pressed during mouse movement? END ' Form_MouseMove()
Since the component WebView1 (gb.qt4.webkit) already uses the mouse wheel to scroll vertically through the web page, the zoom function had to be switched on or off with a switch in order to be able to work with the event MouseWheel(). The control key (Ctrl, Ctrl) is used as a switch. The event component_MouseWheel () refers to the WebView component mentioned above. The zoom factor is only changed if the CTRL key is held down at the same time as the mouse wheel is turned, otherwise the original scroll function for the content of the web page would be active:
 Public Sub WebView1_MouseWheel()  If Mouse.Control Then ' CTRL key (additional) pressed?  Select Case Mouse.Delta  Case -1  If WebView1.Zoom < 2.26 Then  WebView1.Zoom = Round(WebView1.Zoom - Mouse.Delta / 4, -2)  Endif  Case +1  If WebView1.Zoom > 0.61  WebView1.Zoom = Round(WebView1.Zoom - Mouse.Delta / 10, -2)  Endif  End Select  Endif ' Mouse.Control = True?  End ' WebView1_MouseWheel()
You can use the Mouse.Middle property to determine whether the middle mouse button - the mouse wheel - was pressed over a component.