Results 1 to 6 of 6

Thread: [RESOLVED] Sliding panel problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    Resolved [RESOLVED] Sliding panel problem

    Hello everybody,

    I am trying to make a sliding menu using a panel. I set up a form a new panel with size: 181,107, location 180,-95 and the following code:

    Private Sub Panel1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseEnter
    For i = -95 To 0
    Panel1.Location = New Point(180, i)
    Threading.Thread.Sleep(1)
    Next
    End Sub

    Private Sub Panel1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseLeave
    For i = 0 To 95
    Panel1.Location = New Point(180, -i)
    Threading.Thread.Sleep(1)
    Next
    End Sub

    It works fine until I add a control to the panel. If I add any control and the mouse gets over that control it doesn't work any more and it goes up and down. I assume that when mouse enters the controls then the mouse leave of the panel is activated.

    Any idea to make it work?

    thx

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Sliding panel problem

    try this:

    Code:
    Private Sub Panel1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseLeave
        Dim p As Point = Panel1.PointToClient(Cursor.Position)
        If Not Panel1.Region.IsVisible(p) Then
            For i = 0 To 95
                Panel1.Location = New Point(180, -i)
                Threading.Thread.Sleep(1)
            Next
        End If
    End Sub
    **edited**
    Last edited by .paul.; Dec 6th, 2012 at 04:00 AM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    Re: Sliding panel problem

    I get this error: Object reference not set to an instance of an object. - on the line: If Not Me.Region.IsVisible(p) Then

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Sliding panel problem

    Quote Originally Posted by ovi_gm View Post
    I get this error: Object reference not set to an instance of an object. - on the line: If Not Me.Region.IsVisible(p) Then
    try the edited version. post #2

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Sliding panel problem

    ok. as my code in post #2 didn't work (it was copied + pasted from a similar project i wrote, + untested), i had another look + came up with this:

    Code:
    Public Class Form1
    
        Dim ignore As Boolean = False
    
        Private Sub Panel1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseEnter
            If Not ignore Then
                For i = -95 To 0
                    Panel1.Location = New Point(180, i)
                    Threading.Thread.Sleep(1)
                Next
            End If
        End Sub
    
        Private Sub Panel1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseLeave
            Dim p As Point = Me.PointToClient(Cursor.Position)
            If Not Panel1.Bounds.Contains(p) Then
                ignore = False
                For i = 0 To 95
                    Panel1.Location = New Point(180, -i)
                    Threading.Thread.Sleep(1)
                Next
            Else
                ignore = True
            End If
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Panel1.Location = New Point(180, -95)
        End Sub
    
    End Class

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    Re: Sliding panel problem

    Hooray! It works. Thank's a lot. You're great.

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width