-1

Is it possible to animate the panel width for three seconds or depending on the number of seconds I pass on the method/function?

I'm currently using timer to change the width but it doesn't have specific number of seconds to finish the animation.

This is my current code:

Private Sub Button1_Click()
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick()
    If Panel1.Width < 50 Then
        Panel1.Width += 10
    Else
        Me.Dispose()
        Timer1.Enabled = Flase
    End If
End Sub

What i want is to have a function like this

Private Sub AnimateWidth(ByRef pnl As Panel, ByVal MaxWidth As Integer, ByVal NumberOfSeconds as Double)
    'This is where I'm Lost. I dont have any idea what to do
End Sub
15
  • This is basic mathematics, and I mean primary school stuff. You have a number of pixels to move and a number of seconds over which to move. Those are fixed. The variables are the Interval of the Timer, which determines the number of Tick events per second, and the number of pixels to move on each Tick. You don't need help with determining which combinations of those two variables will give you the desired result. Jan 11, 2019 at 9:48
  • Do you mean: you have a period of time (3 seconds) and you need to expand your panel up to a specific measure in this lapse of time, or should it grow to an indefinite measure until the given interval elapses?
    – Jimi
    Jan 11, 2019 at 10:07
  • @Jimi Yes i want it to expand to a specific measure for 3 seconds.
    – JSin
    Jan 11, 2019 at 10:23
  • @jmcilhinney if it's so basic then why can't you just show and teach me or anyone who will have this kind of problem, you know, those who are VERY NEW to programming how its done, rather than showing everyone else how inferior you think I am to you. Thanks BTW.
    – JSin
    Jan 11, 2019 at 10:27
  • Because I'm not here to spoon-feed people who aren't prepared to think for themselves. I commented specifically to point out that this is not actually a programming problem, so the fact that you're new to programming is completely irrelevant. As I said, it's a basic maths problem and I'll wager that you're not new to basic maths. Writing the code is not solving the problem. You should be solving the problem before writing any code. You haven't even tried to do that. It's simple multiplication and division. If you really need me to show you how to do that then you have greater issues. Jan 11, 2019 at 10:33

1 Answer 1

0
Public Sub FadeIn(ByVal TotalSeconds As Single, ByRef frm As Form)
    If TotalSeconds = 0 Then
        frm.Opacity = 1
        Exit Sub
    End If
    Dim [then] As Double = DateAndTime.Timer
    Dim difference As Double = 0
    Do While difference < 1
        frm.Opacity = difference
        difference = (DateAndTime.Timer - [then]) / TotalSeconds
        System.Threading.Thread.Sleep(10)
    Loop
    frm.Opacity = 1
End Sub
1
  • @jmcilhinney i was talking about something like this dad.
    – JSin
    Jan 12, 2019 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.