[Gambas-user] User control disappears when moved by mouse

T Lee Davidson t.lee.davidson at gmail.com
Mon Jun 12 20:54:28 CEST 2023


On 6/12/23 12:00, Claus Dietrich wrote:
> When I move a user control (.i.e. a button ) on its form with following code
> 
> Public Sub Button1_MouseMove()
> 
>    If Mouse.left = True Then
>       Button1.Move(Mouse.screenx - Mouse.startx + Mouse.X, Mouse.Screeny - Mouse.StartY + Mouse.y)
>    End If
> 
> End
> 
> the user control disappears at some positions and when I lift the mouse button in such a moment the user control disappears 
> completely. That means, that it is not displayed any longer and also stops to raise mouse events.
> 
> It happens on Mint Cinnamon, Mate an Kubuntu and also with labels, no matter whether I use QT or GTK. Is it a bug? What can be 
> done to avoid this behaviour?
> 
> Best regards
> 
> Claus

It appears the formula you are using, to calculate the new position to which to move the Button, is faulty. The Button_Move 
method takes X and Y parameters that are relative to the button's parent, ie. the main form, not the entire screen.

With your current code, move the button close to the top left corner of the form until it disappears and then let go of the left 
mouse button. Then, enlarge the application window by dragging the lower right corner. You will see that the button has been 
moved to an unexpected location and was hidden until the window was enlarged.

With the following code, you can see the mouse location properties vacillating between positive and negative numbers. (Perhaps 
you won't see that, but it is what I see here with Qt.)

[code]
Public Sub Button1_MouseMove()

   Dim sPattern As String = "ScreenX: &1, StartX: &2, X: &3; ScreenY: &4, StartY: &5, Y: &6"

   If Mouse.left = True Then
      Button1.Move(Mouse.screenx - Mouse.startx + Mouse.X, Mouse.Screeny - Mouse.StartY + Mouse.y)
      Print Subst(sPattern, Mouse.ScreenX, Mouse.StartX, Mouse.X, Mouse.ScreenY, Mouse.StartY, Mouse.Y)
   End If

End
[/code]


-- 
Lee



More information about the User mailing list