How best to move a control

Post Reply
bill-lancaster
Posts: 46
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

How best to move a control

Post by bill-lancaster » Friday 28th December 2018 12:07pm

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.

vuott
Posts: 20
Joined: Wednesday 05th April 2017 6:07pm

Re: How best to move a control

Post by vuott » Friday 28th December 2018 7:25pm

...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

bill-lancaster
Posts: 46
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: How best to move a control

Post by bill-lancaster » Saturday 29th December 2018 8:43am

Thank you very much vuott.

User avatar
Quincunxian
Posts: 23
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: How best to move a control

Post by Quincunxian » Monday 31st December 2018 11:11pm

Hi Bill,
Now that vuott has provided a good solution.....
Just out of curiosity, why do you want to move a label ?
Cheers - Quin.
I code therefore I am

bill-lancaster
Posts: 46
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: How best to move a control

Post by bill-lancaster » Friday 04th January 2019 11:44am

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.

User avatar
Quincunxian
Posts: 23
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: How best to move a control

Post by Quincunxian » Monday 07th January 2019 12:07am

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.
Cheers - Quin.
I code therefore I am

bill-lancaster
Posts: 46
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: How best to move a control

Post by bill-lancaster » Monday 07th January 2019 1:22pm

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

User avatar
Quincunxian
Posts: 23
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: How best to move a control

Post by Quincunxian » Wednesday 09th January 2019 10:46pm

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.
Cheers - Quin.
I code therefore I am

Post Reply