Re: animate icon from a pint to other point on form
Use a Timer control and move to desired position on each Timer event.
So you have an offset X1, Y1 and you need to move to X2,Y2
Calculate the needed step size for both X and Y
And increase the Left and Top property on every tick of the Timer
Re: animate icon from a pint to other point on form
Originally Posted by Arnoutdv
Use a Timer control and move to desired position on each Timer event.
So you have an offset X1, Y1 and you need to move to X2,Y2
Calculate the needed step size for both X and Y
And increase the Left and Top property on every tick of the Timer
Not for me, and my knoledgment.
Tks in other case.
Re: animate icon from a pint to other point on form
Code:
Option Explicit
Private WithEvents mTimer As Timer
Private WithEvents mCommand As CommandButton
Private m_lStepX As Long, m_lStepY As Long
Private Sub Form_Load()
Me.ScaleMode = vbTwips
Set mTimer = Controls.Add("VB.Timer", "Timer1")
Set mCommand = Controls.Add("VB.CommandButton", "Command1")
mCommand.Visible = True
mCommand.Caption = "Click Me"
End Sub
Private Sub mCommand_Click()
Dim X1 As Long, Y1 As Long, X2 As Long, Y2 As Long
' The current location
X1 = mCommand.Left: Y1 = mCommand.Top
' The destination
X2 = Me.ScaleWidth - mCommand.Width
Y2 = Me.ScaleHeight - mCommand.Height
' 50 ticks per second
mTimer.Interval = 20
' Move in 250 ticks (5 seconds)
m_lStepX = (X2 - X1) / 250
m_lStepY = (Y2 - Y1) / 250
mCommand.Enabled = False
mTimer.Enabled = True
mCommand.Caption = "Resize Form"
Me.Caption = "Resize the form!"
End Sub
Private Sub mTimer_Timer()
With mCommand
.Top = .Top + m_lStepY
.Left = .Left + m_lStepX
If .Top >= Me.ScaleHeight - .Height Then m_lStepY = -m_lStepY: .Top = Me.ScaleHeight - .Height
If .Top <= 0 Then m_lStepY = -m_lStepY
If .Left >= Me.ScaleWidth - .Width Then m_lStepX = -m_lStepX: .Left = Me.ScaleWidth - .Width
If .Left <= 0 Then m_lStepX = -m_lStepX
End With
End Sub
Re: animate icon from a pint to other point on form
Originally Posted by arnoutdv
Code:
option explicit
private withevents mtimer as timer
private withevents mcommand as commandbutton
private m_lstepx as long, m_lstepy as long
private sub form_load()
me.scalemode = vbtwips
set mtimer = controls.add("vb.timer", "timer1")
set mcommand = controls.add("vb.commandbutton", "command1")
mcommand.visible = true
mcommand.caption = "click me"
end sub
private sub mcommand_click()
dim x1 as long, y1 as long, x2 as long, y2 as long
' the current location
x1 = mcommand.left: Y1 = mcommand.top
' the destination
x2 = me.scalewidth - mcommand.width
y2 = me.scaleheight - mcommand.height
' 50 ticks per second
mtimer.interval = 20
' move in 250 ticks (5 seconds)
m_lstepx = (x2 - x1) / 250
m_lstepy = (y2 - y1) / 250
mcommand.enabled = false
mtimer.enabled = true
mcommand.caption = "resize form"
me.caption = "resize the form!"
end sub
private sub mtimer_timer()
with mcommand
.top = .top + m_lstepy
.left = .left + m_lstepx
if .top >= me.scaleheight - .height then m_lstepy = -m_lstepy: .top = me.scaleheight - .height
if .top <= 0 then m_lstepy = -m_lstepy
if .left >= me.scalewidth - .width then m_lstepx = -m_lstepx: .left = me.scalewidth - .width
if .left <= 0 then m_lstepx = -m_lstepx
end with
end sub
great!
But this move a button, instead to move a icon?
i just have in a specified position..
Re: animate icon from a pint to other point on form
It's just a sample about moving a control on the screen.
An icon is represented somewhere I assume?
In a picture control? Then move the picture control.
If it's part a ListView or FlexGrid then you can not move the icon freely around, without some additional coding.
Re: animate icon from a pint to other point on form
Originally Posted by Arnoutdv
It's just a sample about moving a control on the screen.
An icon is represented somewhere I assume?
In a picture control? Then move the picture control.
If it's part a ListView or FlexGrid then you can not move the icon freely around, without some additional coding.
Your code is very professional...
but i need to move a simple image (in image1-image) from a corner to other corner only just once, Is very simple for You, or not?
Naturally with the animation of the path.
See the image.
I need to decide wich one position initial and a finale position via code
Last edited by luca90; Feb 24th, 2022 at 02:30 PM.