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.
How best to move a control
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: How best to move a control
...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
Europaeus sum !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: How best to move a control
Thank you very much vuott.
- Quincunxian
- Posts: 174
- Joined: Sunday 25th June 2017 12:14am
- Location: Western Australia
Re: How best to move a control
Hi Bill,
Now that vuott has provided a good solution.....
Just out of curiosity, why do you want to move a label ?
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
I code therefore I am
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: How best to move a control
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.
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.
- Quincunxian
- Posts: 174
- Joined: Sunday 25th June 2017 12:14am
- Location: Western Australia
Re: How best to move a control
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.
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
I code therefore I am
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: How best to move a control
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
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
- Quincunxian
- Posts: 174
- Joined: Sunday 25th June 2017 12:14am
- Location: Western Australia
Re: How best to move a control
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.
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
I code therefore I am