|
-
Dec 6th, 2012, 03:17 AM
#1
Thread Starter
Addicted Member
[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
-
Dec 6th, 2012, 03:55 AM
#2
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.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 6th, 2012, 03:59 AM
#3
Thread Starter
Addicted Member
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
-
Dec 6th, 2012, 04:10 AM
#4
Re: Sliding panel problem
 Originally Posted by ovi_gm
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 6th, 2012, 04:26 AM
#5
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 6th, 2012, 05:03 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|