Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Ha! It slides into eternity! (http://www.programmingforums.org/showthread.php?t=11714)

emdiesse Oct 26th, 2006 7:53 PM

Ha! It slides into eternity!
 
I have a context menu on my tray icon with the words show and hide depending upon where the form is it will either show or hide the form by sliding it by the system tray.

Below is code I have so far it didn't work but I made an attempt. It just slides and never stops I believe.

How do I accomplish this task. Thank you

:

    Dim workingArea As Rectangle = Screen.PrimaryScreen.WorkingArea
    Dim LocationTop, LocationBottom As Point
    Dim FormShown As Boolean
    Dim VerticalLocation, i As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        VerticalLocation = Me.Height
        LocationTop = New Point(workingArea.Width - Me.Width, workingArea.Height - Me.Height)
        LocationBottom = New Point(workingArea.Width - Me.Width, workingArea.Height)
        Me.Location = LocationTop
        FormShown = True
        MenuItem1.Text = "Hide"
    End Sub
    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        If FormShown = True Then
            SlideTimer.Start()
            Do While i <= 64
                VerticalLocation = VerticalLocation - 2
                Me.Location = New Point(workingArea.Width - Me.Width, workingArea.Height - VerticalLocation)
            Loop
            FormShown = False
            Me.Hide()
            MenuItem1.Text = "Show"
        Else
            Me.Show()
            SlideTimer.Start()
            Do While i <= 64
                VerticalLocation = VerticalLocation + 2
                Me.Location = New Point(workingArea.Width - Me.Width, workingArea.Height - VerticalLocation)
            Loop
            Me.Location = LocationTop
            FormShown = True
            MenuItem1.Text = "Hide"
        End If
    End Sub

    Private Sub SlideTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SlideTimer.Tick
        i = 0
        Do While i < 64
            i = i + 1
        Loop
            SlideTimer.Stop()
    End Sub


melbolt Nov 1st, 2006 1:02 AM

here is what's happening, you fire off your timer, instantly the value of i reaches 64 in the timer tick handler. after that completes it continues on the following line where you have a "<=" the equals part of this is satisfied because the value is 64. since you never increment anymore at this point you have what is known as a "forever loop" and it just keeps right on going lol.


All times are GMT -5. The time now is 1:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC