I want my users to be able to move lines about
they are generally diagonal lines, but some will be horizontal or vertical
I have persuaded the mouse down, up and drag events to give me useful numbers
indeed I can move other controls based on these numbers
but I want to move the line
I tried setting its LEFT property, and invalidating it, bit it stubbornly refuses to move
any advice would be most gratefully received
thanks
Mike
[quote=90040:@Mike McPherson]I want my users to be able to move lines about
they are generally diagonal lines, but some will be horizontal or vertical
I have persuaded the mouse down, up and drag events to give me useful numbers
indeed I can move other controls based on these numbers
but I want to move the line
I tried setting its LEFT property, and invalidating it, bit it stubbornly refuses to move[/quote]
Although the Line object has left and Top, the real values to modify to move it are X1-Y1 and X2-Y2 which indicate both ends of the line.
This code in a button action will move a line by 10 points on each click :
Sub Action()
Line1.X1 = Line1.X1+10
Line1.X2 = Line1.X2+10
End Sub
To move it with the mouse, consider these values. The tricky part is to move all 4 instead of simply left and top.
Left = X1
Top = Y1
Width = X2-X1 or X1-X2
Height = Y2-Y1 or Y1-Y2
Width and height depend on the orientation of the line.
aha
I tried what you suggested
amazed that you have to move the end-points rather than the top and left
- but it works so I’m not complaining
thanks!
Because the line is not a rectangle, which other controls are. Even an oval is actually defined by a virtual rectangle tangent to it.
If a line never changed orientation, it could move the same way, but let us imagine you want one end of the line to stay fixed, and the other end to follow the mouse cursor. Then you must have two sets of coordinates. Just like in regular geometry.
Line drawing is optimized for orientation. Shape drawing is optimized for sizing. Shapes can’t be easily rotated, while lines are assumed to often be rotated.
Michel, Eduardo,
thanks for the information
I do understand that you need two sets of coordinates for a line, but I (wrongly) assumed that setting the coordinates of the apparent containing rectangle would also move the line
it does in the designer, but not at run time
anyway, got past that now
next issue is
I can move the line, but it seems to disappear while I’m dragging it
it only re-appears when I stop dragging
my code:
mouse down:
// save in a check box so I can see it's happened
mouseDownState.Value = True
mouseDownState.refresh
// save start coords
mouseXstart.Text = str(x)
mouseYstart.Text = str(y)
mouseXstart.Refresh
mouseYstart.Refresh
// save line start and end Y
lineY1start.text = str(sunlightLine.y1)
lineY2start.text = str(sunlightLine.y2)
return true
mouse drag:
dim newY as integer
// show drag coordinates
Main.mouseX.Text = str(x)
Main.mouseY.Text = str(y)
Main.mouseX.Refresh
Main.mouseY.Refresh
// reposition line as mouse moves
// only moves in y direction
newY = y - val(Main.mouseYstart.Text)
Main.mouseYnew.Text = str(newY)
Main.mouseYnew.Refresh
sunlightLine.Y1 = val(LineY1start.text) + newY
if sunlightLine.Y1 < 50 + sunlightLine.BorderWidth/2 then
sunlightLine.Y1 = 50 + sunlightLine.BorderWidth/2
end if
if sunlightLine.Y1 > 100 then
sunlightLine.Y1 = 100
end if
sunlightLine.Y2 = sunlightLine.Y1
sunlightLine.refresh
// adjust neighbour lines as well
sunriseLine.Y2 = sunlightLine.Y1
sunsetLine.Y1 = sunlightLine.Y1
sunriseLine.refresh
sunsetLine.refresh