Question

What event(s) would I use to handle hiding a button/component that is inside this panel? This is a sliding panel that when the user hovers over, it expands and when the mouse exits, it collapses.

The problem is I don't know how to keep the components from showing until it is expanded.

 Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Panel1.Dock = DockStyle.Left
        Timer3.Enabled = True
    End Sub


    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If Panel1.Width < 150 Then
            Panel1.Width = Panel1.Width + 100
        ElseIf Panel1.Width = 150 Then
            Timer1.Enabled = False
        End If
    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        If Panel1.Width >= 100 Then
            Panel1.Width = Panel1.Width - 50
            If Panel1.Width < 100 And Panel1.Width > 25 Then
                Panel1.Width = Panel1.Width - 1
            End If

        ElseIf Panel1.Width = 25 Then
            Timer2.Enabled = False
        End If
    End Sub


    Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
        If Panel1.ClientRectangle.Contains(Panel1.PointToClient(MousePosition)) Then
            If Not Timer1.Enabled AndAlso Panel1.Width < 150 Then
                Timer1.Enabled = True
                Timer2.Enabled = False
            End If
        Else
            If Not Timer2.Enabled AndAlso Panel1.Width > 25 Then
                Timer1.Enabled = False
                Timer2.Enabled = True
            End If
        End If
    End Sub


End Class
Was it helpful?

Solution

You should probably rename your timers to keep them straight, something like SlideOpenTimer and SlideCloseTimer, etc. Would make it easier to understand what the timers are for.

I re-worked your timer events to hide the ListBox when the closing timer starts and to show the ListBox when the panel reaches its full width:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  If Panel1.Width < 100 Then
    Panel1.Width += 50
  ElseIf Panel1.Width < 150 Then
    Panel1.Width += 25
  ElseIf Panel1.Width >= 150 Then
    Timer1.Enabled = False
    ListBox1.Visible = True
  End If
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
  If ListBox1.Visible Then
    ListBox1.Visible = False
  End If
  If Panel1.Width > 100 Then
    Panel1.Width -= 50
  ElseIf Panel1.Width > 25 Then
    Panel1.Width -= 25
  ElseIf Panel1.Width <= 25 Then
    Timer2.Enabled = False
  End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top