Hi all
Is it possible to move a button code ?
I have a matrix of lines which I want to drag a button into one of the squares in the matrix and I want to snap to grid.
So I can read the position and see which is the closest square when I release the dragging of the button. I then want it to align into that block.
I cannot find an option , unless I re-initialize the button . the button is created in the designer designer
Thank you
Is it possible to move a button code ?
I have a matrix of lines which I want to drag a button into one of the squares in the matrix and I want to snap to grid.
So I can read the position and see which is the closest square when I release the dragging of the button. I then want it to align into that block.
I cannot find an option , unless I re-initialize the button . the button is created in the designer designer
Thank you
B4X:
Private Sub Button2_MouseDragged (EventData As MouseEvent)
' Log("mouse dragged")
Dim view As B4XView = Sender
Dim pd As PositionData = view.Tag
Dim ParentX As Int = EventData.X + view.Left
Dim ParentY As Int = EventData.Y + view.Top
view.Left = ParentX - pd.PressedX
view.Top = ParentY - pd.PressedY
End Sub
Private Sub Button2_MousePressed (EventData As MouseEvent)
Log("Button2_MousePressed")
' Log(EventData.PrimaryButtonPressed)
Dim view As B4XView = Sender
Dim pd As PositionData
pd.PressedX = EventData.X
pd.PressedY = EventData.Y
view.Tag = pd
Log(view.Tag)
End Sub
Private Sub Button2_MouseReleased (EventData As MouseEvent)
Dim view As B4XView = Sender
Log("released")
Log(EventData.X)
Log(EventData.Y)
Dim pd As PositionData
pd.PressedX = EventData.X
pd.PressedY = EventData.Y
view.Tag = pd
End Sub
Last edited: