Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a code to give a sliding effect to 5 command buttons. It runs fine with default background but when i change the opacity of the form OR put a picture in the background it behaves slower rather much slower than what it does normally. What might be the issue? Any ideas to resolve it. Here is the code.



VB
Public Class Form1
    Dim slidevar As Integer = -10
    Dim slidevar1 As Integer = -60
    Dim slidevar2 As Integer = -120
    Dim slidevar3 As Integer = -180
    Dim slidevar4 As Integer = -240
    Dim delayvar As Integer = -300
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Button1.Location = New Point(-1000, 10)
        Button2.Location = New Point(-1000, 80)
        Button3.Location = New Point(-1000, 120)
        Button4.Location = New Point(-1000, 160)
        Button5.Location = New Point(-1000, 200)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub

    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
        slidevar = 0
        slidevar1 = 0
        slidevar2 = 0
        slidevar3 = 0
        slidevar4 = 0

        Button1.Location = New Point(-1000, 10)
        Button2.Location = New Point(-1000, 80)
        Button3.Location = New Point(-1000, 120)
        Button4.Location = New Point(-1000, 160)
        Button5.Location = New Point(-1000, 200)
        Timer1.Enabled = True


    End Sub

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


        If slidevar < 65 Then
            Button1.Location = New Point(slidevar, 10)
            slidevar += 6
            If slidevar4 > 65 Then
                Timer1.Enabled = False
            End If
        End If


        For delayvar = 1 To 100
        Next

        If slidevar1 < 65 Then
            Button2.Location = New Point(slidevar1, 80)
            slidevar1 += 5
        End If




        For delayvar = 1 To 100
        Next
        If slidevar2 < 65 Then
            Button3.Location = New Point(slidevar2, 120)
            slidevar2 += 4
        End If


        For delayvar = 1 To 100
        Next
        If slidevar3 < 65 Then
            Button4.Location = New Point(slidevar3, 160)
            slidevar3 += 3
        End If


        For delayvar = 1 To 100
        Next
        If slidevar4 < 65 Then
            Button5.Location = New Point(slidevar4, 200)
            slidevar4 += 2
        End If



    End Sub
End Class
Posted
Comments
Alan Burkhart 27-Aug-11 1:04am    
I tried it with and without a background image. Took between 3 and 4 seconds either way. Keep in mind that every time the buttons move, the Paint event is firing.

1 solution

Have a look at your form's DoubleBuffered property this should help with the repaint
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900