Slide effect

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 5025 Views - Last Post: 31 January 2013 - 11:44 AM Rate Topic: -----

#1 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 315
  • Joined: 19-January 12

Slide effect

Posted 23 January 2013 - 10:55 AM

I am trying to achieve a slide effect for a panel named "sidebar"
I used a timer but the panel does not slide into view but just appears in its new point.
Basicaly it should slide from point -230,0 into point 0,0
What is wrong here?
Private Sub SlideButt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SlideButt1.Click
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim xy As Integer
        If xy < 1 Then
            Sidebar.Location = New Point(xy, 0)
            Timer1.Stop()
        Else
            xy = -230 + 1
        End If


This post has been edited by Bluezap: 23 January 2013 - 10:57 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Slide effect

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Slide effect

Posted 23 January 2013 - 10:58 AM

Hint: Place a Breakpoint on the timer tick method and step-through the code.
Link to Debugging Tutorial
Was This Post Helpful? 0
  • +
  • -

#3 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 315
  • Joined: 19-January 12

Re: Slide effect

Posted 23 January 2013 - 11:01 AM

View PostAdamSpeight2008, on 23 January 2013 - 10:58 AM, said:

Hint: Place a Breakpoint on the timer tick method and step-through the code.
Link to Debugging Tutorial

what i understood by doing this is that +1 gets added to -230 at once and not in series.
I don't seem to understand how to solve this situation.
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Slide effect

Posted 23 January 2013 - 11:07 AM

View PostBluezap, on 23 January 2013 - 11:55 AM, said:

I am trying to achieve a slide effect for a panel named "sidebar"
I used a timer but the panel does not slide into view but just appears in its new point.
Basicaly it should slide from point -230,0 into point 0,0
What is wrong here?
[/code]

What is the initial value of variable xy?
Hint: You have just DIMed it.

Place a breakpoint on line 7 and single-step your code.

If you aren't sure how to do this, see the Debugging Skills Tutorial.

View PostBluezap, on 23 January 2013 - 12:01 PM, said:

View PostAdamSpeight2008, on 23 January 2013 - 10:58 AM, said:

Hint: Place a Breakpoint on the timer tick method and step-through the code.
Link to Debugging Tutorial

what i understood by doing this is that +1 gets added to -230 at once and not in series.

Actually, it doesn't. Try again. Place the breakpoint and see where you get to on the first time through.
Was This Post Helpful? 0
  • +
  • -

#5 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 315
  • Joined: 19-January 12

Re: Slide effect

Posted 23 January 2013 - 11:12 AM

Tried
  Dim xy As Integer = -230
        If xy > 1 Then
            Sidebar.Location = New Point(xy, 0)
            Timer1.Stop()
        Else
            xy = xy + 1
        End If


Still no luck :(/>

I used F8 to step through the code but i don't seem to understand why this logic is wrong? :/

This post has been edited by AdamSpeight2008: 23 January 2013 - 11:10 AM

Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Slide effect

Posted 23 January 2013 - 11:15 AM

Don't change the code, examine the code, Step Through the code.

Write down what you think the progress of the code should be, at each step.
Examine what the contents are of each variable.
What is the scope of the variable used?
Predict what will happen next in the execution, does what actually occurs match the prediction?
Was This Post Helpful? 0
  • +
  • -

#7 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 315
  • Joined: 19-January 12

Re: Slide effect

Posted 23 January 2013 - 11:23 AM

used a loop but still no results. Went through the code step by step, seems to be correct but no slide effect :/

        Dim xy As Integer = -230
        Do Until xy > 0
            xy = xy + 1
        Loop
        If xy > 0 Then
            Sidebar.Location = New Point(xy, 0)
            Timer1.Stop()
        End If


Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Slide effect

Posted 23 January 2013 - 11:29 AM

You're not listening to what I say.

STOP Changing the code. (for now).

You need to THINK about the code and understand what is actually happening.

Don't change a single character of the code, until you understand it completely.

Answer the follow questions.

When is the method executed? Is it executed more than once?
What actual happens on each of the lines?

Write a reply with your answers.

This post has been edited by AdamSpeight2008: 23 January 2013 - 02:07 PM

Was This Post Helpful? 0
  • +
  • -

#9 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Re: Slide effect

Posted 23 January 2013 - 01:14 PM

I think there is no need of timer control

you can do it like this

Do Until sidebar.location.x = 0 
      sidebar.location.x += 1
Loop


if you want to decrease the speed of the animation then you should decrease "1"

Sorry to say but I have not checked the code, but i think it should work
This might help you

This post has been edited by Vishal1419: 23 January 2013 - 01:17 PM

Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Slide effect

Posted 23 January 2013 - 02:06 PM

Some of you need to analyse the code the OP has supplied.
It'll be more beneficial to them, if they think about the code.

Programming is more about thinking, analysis and designing solutions, that actually writing code.
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Slide effect

Posted 23 January 2013 - 03:17 PM

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim xy As Integer       'this will always have a default value of 0
        If xy < 1 Then          '.. so this is always true
            Sidebar.Location = New Point(xy, 0)     'and this will always move to (0,0) immediately
            Timer1.Stop()       '.. and stop immediately
        Else
            xy = -230 + 1       'this never occurs
        End If
    End Sub


    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim xy As Integer = Sidebar.Left        'it's current position
        If xy < 1 Then
            Sidebar.Left += 1   'push it slightly to the right
            '(no need to create a new point)
            '(we cannot increment X in this way: .Location.X += 1 )
        Else
            Timer1.Stop()       'the animation has finished
            'xy = -230 + 1 'this shouldn't happen here; presumably a button 
            'or some other event would re-position Sidebar to -230.
            'I assume you don't what this to happen when the Timer is stopped,
            'otherwise it will just jump back as soon as the animation finishes(?).
        End If
    End Sub


BTW
Dim xy As Integer = Sidebar.Left        'it's current position


It would be possibly to store xy once only and then use it to change the Left position until xy = 1. However, there may be something else that will change the Left position, so it is better to just re-read the .Left value each time the Timer fires.
Was This Post Helpful? 0
  • +
  • -

#12 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 315
  • Joined: 19-January 12

Re: Slide effect

Posted 24 January 2013 - 07:38 PM

can someone explain why this doesn't work?
don't seem to understand this whole concept properly.
 Dim xy As Integer = -230
        Do Until xy > 1
            If xy > 1 Then
                Timer1.Stop()
            Else
                xy = xy + 1
                Sidebar.Location = New Point(xy, 0)
            End If
        Loop
    End Sub


Was This Post Helpful? 0
  • +
  • -

#13 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,099
  • Joined: 02-July 08

Re: Slide effect

Posted 24 January 2013 - 08:50 PM

Think about the logic of the first part - the do until. It stops the loop and the xy > 1 Then does not get to execute.
Was This Post Helpful? 0
  • +
  • -

#14 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Slide effect

Posted 24 January 2013 - 10:36 PM

View PostBluezap, on 24 January 2013 - 08:38 PM, said:

can someone explain why this doesn't work?
don't seem to understand this whole concept properly.

Have a look at the comments I put into your code below:

 Dim xy As Integer = -230
    'at this pojnt, xy = -230
    ' This will be true EVERY time the Timer Ticks
        Do Until xy > 1
            If xy > 1 Then
    'You will bever execute this part of the loop because as soon as
    ' xy is > 1, the loop will stop looping. This is because it
    ' is a Do UNTIL loop.
                Timer1.Stop()
            Else
    'This part of the loop will execute 231 times, very quickly.
    'It does not execute once per Timer Tick, because the entire loop
    '  is within the Timer Tick handler.
    'Because the Timer does not stop, you will re-enter the 
    '  Timer Tick handler again and again, and the Dim statement will
    '  reset xy to -230. Because thes happens so fast, you'll either
    '  see the Slidebar "snap" into position, or you woun't see it at all,
    '  depending on the Interval set in the Timer control. Again, remember
    '  that the Timer is never going to stop.
                xy = xy + 1
                Sidebar.Location = New Point(xy, 0)
            End If

        Loop
    End Sub


Here's some pseudo-code to think about.

    Dim Direction as Integer = 1
    Dim HiddenPosition as Integer = -230
    Dim ShowingPosition as Integer = 1

    Sub Timer_Tick()
      Add Direction to SlideBar.Left
      If SlideBar.Left is where you want it
        Stop Timer
      End IF
    End Sub


Now all you need to do is to have a couple of subroutines (Button clicks perhaps), that set the direction and start the timer.
Was This Post Helpful? 0
  • +
  • -

#15 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 315
  • Joined: 19-January 12

Re: Slide effect

Posted 26 January 2013 - 02:21 AM

ok this seemed much easier.
 Do Until sidebar.Width > 217
            sidebar.Width = sidebar.Width + 3
        Loop


thanks anyway :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2