Page 1 of 1

How best to move a control

Posted: Friday 28th December 2018 12:07pm
by bill-lancaster
I want to click on a label control and move it to a different position on a form, just the way it happens in the IDE.
I've tried a few things but the result is rather jerky.
Any suggestions welcome.

Re: How best to move a control

Posted: Friday 28th December 2018 7:25pm
by vuott
...a little code:
Private Label1 As Label
Private spx As Short
Private spy As Short


Public Sub Form_Open()

  With Label1 = New Label(Me) As "Label1"
    .X = 100
    .Y = 100
    .W = 30
    .H = 30
    .Background = Color.Orange
  End With

End


Public Sub Label1_MouseDown()

  spx = Mouse.X
  spy = Mouse.Y

End


Public Sub Label1_MouseMove()

  With Label1
    .X = .X + Mouse.X - spx
    .Y = .Y + Mouse.Y - spy
  End With

End

Re: How best to move a control

Posted: Saturday 29th December 2018 8:43am
by bill-lancaster
Thank you very much vuott.

Re: How best to move a control

Posted: Monday 31st December 2018 11:11pm
by Quincunxian
Hi Bill,
Now that vuott has provided a good solution.....
Just out of curiosity, why do you want to move a label ?

Re: How best to move a control

Posted: Friday 4th January 2019 11:44am
by bill-lancaster
Good question!
I've made a simple family tree project. Sometimes there are more siblings (name etc shown in a label) than will fit across the screen so by moving the labels left or right enables all of the siblings to be viewed.

Re: How best to move a control

Posted: Monday 7th January 2019 12:07am
by Quincunxian
Hi Bill,
You could put the view object where you create your family tree in a scroll view control and in that way you could just have a 'static' tree drawn and the user could just scroll the contents.
Would be interested in seeing the code when you finished as I would be interested in seeing how you handled the data relationship management.

Also I discovered that there is a 'move' procedure in some controls now.
I don't remember it being there but was not specifically looking for it either.
It allows a move with an optional resize which is cool.

From the Gambas wiki:...
Control.Move (gb.qt4)
Sub Move ( X As Integer, Y As Integer [ , Width As Integer, Height As Integer ] )
Moves and/or resizes the control.

Re: How best to move a control

Posted: Monday 7th January 2019 1:22pm
by bill-lancaster
Hello Quin,
My mistake, In fact it was a project where I use mplayer to manage audio. I have a progress bar to show current position in the item and I wanted to be able to move a marker to a stop point underneath the progress bar.
With the family tree project I just change the X value of the labels (together with their vertical & horizontal connecting lines). Your suggestion of a scroll bar could be of interest. The database is a copy of the standard GEDCOM mysql db used in my web based family tree (a free genealogy manager called webtrees). I'd be happy to provide more details if you wish.

I'd be happy to copy you with the project when it's a bit more stable.

Regards
Bill

Re: How best to move a control

Posted: Wednesday 9th January 2019 10:46pm
by Quincunxian
Thanks Bill,
Put me on the list for code sharing once you're done. - Thanks
I collect code snippets and once I have enough of a similar type , I create a "tool-box class" for them.