Slide effect

  • (2 Pages)
  • +
  • 1
  • 2

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

#16 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Re: Slide effect

Posted 26 January 2013 - 02:29 AM

just one more quick question
on sliding back out of view , while in progress the sidebar shows a white blinking trail which is quite annoying. what would be the reason for this? it is like a small lag. anyway of stopping the white lag trail?
 Do Until sidebar.Width < 1
            sidebar.Width = sidebar.Width - 6
        Loop


This post has been edited by Bluezap: 26 January 2013 - 02:29 AM

Was This Post Helpful? 0
  • +
  • -

#17 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

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

Re: Slide effect

Posted 27 January 2013 - 10:10 AM

Try placing an Application.DoEvents after each change of the position. The refresh of the background may not be getting enough CPU cycles to happen.
Was This Post Helpful? 0
  • +
  • -

#18 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1031
  • View blog
  • Posts: 4,013
  • Joined: 02-July 08

Re: Slide effect

Posted 27 January 2013 - 10:26 AM

Application.DoEvents is a bad bandage for these things. This what you telling the compiler to do:

Do this loop and do other stuff that was waiting on us to go ahead and go. So would that make the loop slower?
Was This Post Helpful? 0
  • +
  • -

#19 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Slide effect

Posted 27 January 2013 - 10:46 AM

Bluezap:- Think about the problem as a Function, that gets evaluated on each tick event.

StateNext = ProduceOfNext (StateCurrent)

or as expressed in code
Function ProduceNext(Of StateType )( Current As StateType,
                              ProducerOfNext As Func(of StateType, StateType)
                                   ) As StateType
  Return ProducerOfNext( Current )
End Function



Write us a function that produces the next state, or what is needed to move the control to the next location.

This post has been edited by AdamSpeight2008: 27 January 2013 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

#20 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Re: Slide effect

Posted 30 January 2013 - 11:20 PM

I don't understand, can someone elaborate? the white lag occurs even if the visibility of an object is set to false/true.
I need to get rid of this all together :/
Was This Post Helpful? 0
  • +
  • -

#21 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: Slide effect

Posted 31 January 2013 - 04:29 AM

I read somewhere recently that making a double-adjustment like the following can improve it:

Do Until sidebar.Width < 1
    sidebar.Width = sidebar.Width - 8
    sidebar.Width = sidebar.Width + 2
Loop

I have no idea currently why, or if, this works but thought it worth trying.

Otherwise it might be worth trying Thread.Sleep(50) between each update. Again, I don't know if this will make a difference.

This post has been edited by andrewsw: 31 January 2013 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

#22 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

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

Re: Slide effect

Posted 31 January 2013 - 07:02 AM

View Post_HAWK_, on 27 January 2013 - 11:26 AM, said:

Application.DoEvents is a bad bandage for these things. This what you telling the compiler to do:

Do this loop and do other stuff that was waiting on us to go ahead and go. So would that make the loop slower?

Yes, it would make the loop slower. I use Application.DoEvents when it is more important to allow something to happen than it is to have a fast loop. Two reasons come immediately to mind.

1. When a control does not update because a tight loop is not allowing it to happen. If I want to see the results of something as it's happening, for example, and have an action that changes a control within the loop, I DO want to see it. If I didn't, I wouldn't have put the control action in the loop in the first place.

2. When a tight loop is not allowing buttons or other controls to receive and act upon user input in a reasonable time, say a Cancel Button, a Minimize Button, or a Close Button, to name just a few, then Application.DoEvents is, to my way of thinking, perfectly justified.

In my opinion, in this case, the "Slide Effect" being visible to the user is more important than the speed of the loop, provided that the loop will still run fast enough to do the job without being too slow in the perception of the user.

So unless you can tell me of some other way to handle such things, I'll continue to use Application.DoEvents, and recommend it when it seems appropriate.

This post has been edited by lar3ry: 31 January 2013 - 07:04 AM

Was This Post Helpful? 1
  • +
  • -

#23 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Slide effect

Posted 31 January 2013 - 11:44 AM

@lar3ry: A much better way for you.

Option Strict On
Option Explicit On

Imports System.Runtime.CompilerServices
Public Module Exts
  <Extension>
  Public Function InContextOf(Of ISC As System.ComponentModel.ISynchronizeInvoke) _
                             (Tsk As Task,
              ByVal InThisContext As ISC,
                     DoThisAction As Action
                                ) As Task
    Return Tsk.ContinueWith(Sub() InThisContext.BeginInvoke(Sub() DoThisAction(), {}))

  End Function

  <Extension()>
  Public Async Function MoveTo(Of T As Control)(ByVal Ctrl As T, NewPosition As Point, OverSec As Integer) As Task
    Const DelayMS = 100
    Dim Steps = (OverSec * (1000 / DelayMS))
    Dim PositionDeltas = New PointF((NewPosition.X - Ctrl.Left), (NewPosition.Y - Ctrl.Top))
    Dim StepSizes = New SizeF(CSng(PositionDeltas.X / Steps), CSng(PositionDeltas.Y / Steps))
    For i = 1 To Steps
      Await Task.Delay(DelayMS).InContextOf(Ctrl, Sub()
                                                    Ctrl.Left = CInt(Ctrl.Left + StepSizes.Width)
                                                    Ctrl.Top = CInt(Ctrl.Top + StepSizes.Height)
                                                  End Sub)
    Next
  End Function
End Module



The two buttons slide move at the same time.

Option Strict On
Option Explicit On

Imports WindowsApplication4.Exts

Public Class Form1
  Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If Me.Button1.Left = 0 Then
      Await Task.WhenAll({Me.Button1.MoveTo(New Point(100, 100), 10),
                            Me.Button2.MoveTo(New Point(0, 100), 5)})
    Else

      Await Task.WhenAll({Me.Button1.MoveTo(New Point(0, 0), 10),
                           Me.Button2.MoveTo(New Point(100, 0), 5)})
    End If
  End Sub


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2