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

Bruce Steers bsteers4 at gmail.com
Tue Jun 13 00:40:39 CEST 2023


On Mon, 12 Jun 2023 at 23:31, Bruce Steers <bsteers4 at gmail.com> wrote:

>
>
> On Mon, 12 Jun 2023 at 17:01, Claus Dietrich <claus.dietrich at freenet.de>
> 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 problem is you are using Mouse.ScreenX not Button1.X as the first value
> The button x pos moves relevant to itself not Mouse.screenx.
>
> Try this...  (I used Last not Button1 as then this code works to move any
> control
>
> Public Sub Button1_MouseMove()
>
> If Mouse.Left Then Last.Move(Last.X + (Mouse.X - Mouse.StartX), Last.Y +
> (Mouse.Y - Mouse.StartY))
> End
> BruceS
>

So to clarify...
the calculation  (Mouse.X - Mouse.StartX) is a positive or negative
distance value depending where the mouse moved to horizontally.
So Button1.X += (Mouse.X - Mouse.StartX) moves horizontally with the mouse.
Button1.Y += (Mouse.Y - Mouse.StartY) does the vertical.

Hope that helps
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230612/f797dbe1/attachment-0001.htm>


More information about the User mailing list