Update!
For update see post #5
I've been seeing a few questions about a slideable control such as panels and pictureboxes. So I've decided to do my take on a slideable panel.
Features:
-Slides a panel
Drawbacks:
-It gets a little choppy depending on how fast you want it to slide
Plans:
-None, it's a simple little code to help out those that need it
Notes:
-This assumes that you all ready have a button, a panel, and a timer added to your form with the controls name and 1(ie - button1, panel1, and timer1). I also suggest that if you want to make the slide effect go faster or slower, then change the subtraction in the panel's size rather than changing the timer's interval. It makes it a little less choppy.
Collapses to the left:
Collapses to the right:Code:Option Strict On Option Explicit On Public Class Form1 Private collapsed As Boolean = False Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Panel Dim slidePanel As Panel = Panel1 With slidePanel .Dock = DockStyle.Left .Width = 200 .BorderStyle = BorderStyle.FixedSingle End With 'Timer Dim tmr As Timer = Timer1 With tmr .Enabled = False .Interval = 1 End With 'Button Dim btn As Button = Button1 With btn .Text = "......" .Size = New Size(15, 75) .Anchor = AnchorStyles.Left .Location = New Point(Panel1.Width + 1, CInt(Me.Height / 2 - Button1.Height)) End With End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick If collapsed = False Then If Panel1.Width > 0 Then Panel1.Size = New Size(Panel1.Size.Width - 5, Panel1.Size.Height) Button1.Location = New Point(Panel1.Width + 1, CInt(Me.Height / 2 - Button1.Height)) ElseIf Panel1.Width <= 0 Then Timer1.Enabled = False collapsed = True End If Else If Panel1.Width < 200 Then Panel1.Size = New Size(Panel1.Size.Width + 5, Panel1.Size.Height) Button1.Location = New Point(Panel1.Width + 1, CInt(Me.Height / 2 - Button1.Height)) ElseIf Panel1.Width >= 200 Then Timer1.Enabled = False collapsed = False End If End If End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub End Class
Collapses to the top:Code:Option Strict On Option Explicit On Public Class Form1 Private collapsed As Boolean = False Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim slidePanel As Panel = Panel1 With slidePanel .Dock = DockStyle.Right .Width = 200 .BorderStyle = BorderStyle.FixedSingle End With 'Timer Dim tmr As Timer = Timer1 With tmr .Enabled = False .Interval = 1 End With 'Button Dim btn As Button = Button1 With btn .Text = "......" .Size = New Size(15, 75) .Anchor = AnchorStyles.Right .Location = New Point((Panel1.Location.X - btn.Width) - 1, CInt(Me.Height / 2 - Button1.Height / 2)) End With End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick If collapsed = False Then If Panel1.Width > 0 Then Panel1.Size = New Size(Panel1.Size.Width - 5, Panel1.Size.Height) Button1.Location = New Point((Panel1.Location.X - Button1.Width) - 1, CInt(Me.Height / 2 - Button1.Height / 2)) ElseIf Panel1.Width <= 0 Then Timer1.Enabled = False collapsed = True End If Else If Panel1.Width < 200 Then Panel1.Size = New Size(Panel1.Size.Width + 5, Panel1.Size.Height) Button1.Location = New Point((Panel1.Location.X - Button1.Width) - 1, CInt(Me.Height / 2 - Button1.Height / 2)) ElseIf Panel1.Width >= 200 Then Timer1.Enabled = False collapsed = False End If End If End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub End Class
Collapses to the bottom:Code:Option Strict On Option Explicit On Public Class Form1 Private collapsed As Boolean = False Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim slidePanel As Panel = Panel1 With slidePanel .Dock = DockStyle.Top .Height = 200 .BorderStyle = BorderStyle.FixedSingle End With 'Timer Dim tmr As Timer = Timer1 With tmr .Enabled = False .Interval = 1 End With 'Button Dim btn As Button = Button1 With btn .Text = "......" .Size = New Size(75, 15) .Anchor = AnchorStyles.Right .Location = New Point(CInt(Me.Width / 2 - Button1.Width / 2), Panel1.Height + 1) End With End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick If collapsed = False Then If Panel1.Height > 0 Then Panel1.Size = New Size(Panel1.Size.Width, Panel1.Size.Height - 5) Button1.Location = New Point(CInt(Me.Width / 2 - Button1.Width / 2), Panel1.Height + 1) ElseIf Panel1.Height <= 0 Then Timer1.Enabled = False collapsed = True End If Else If Panel1.Height < 200 Then Panel1.Size = New Size(Panel1.Size.Width, Panel1.Size.Height + 5) Button1.Location = New Point(CInt(Me.Width / 2 - Button1.Width / 2), Panel1.Height + 1) ElseIf Panel1.Height >= 200 Then Timer1.Enabled = False collapsed = False End If End If End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub End Class
Suggestions are welcomed :]Code:Option Strict On Option Explicit On Public Class Form1 Private collapsed As Boolean = False Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim slidePanel As Panel = Panel1 With slidePanel .Dock = DockStyle.Bottom .Height = 200 .BorderStyle = BorderStyle.FixedSingle End With 'Timer Dim tmr As Timer = Timer1 With tmr .Enabled = False .Interval = 1 End With 'Button Dim btn As Button = Button1 With btn .Text = "......" .Size = New Size(75, 15) .Anchor = AnchorStyles.Right .Location = New Point(CInt(Me.Width / 2 - Button1.Width / 2), Panel1.Location.Y - Button1.Height) End With End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick If collapsed = False Then If Panel1.Height > 0 Then Panel1.Size = New Size(Panel1.Size.Width, Panel1.Size.Height - 5) Button1.Location = New Point(CInt(Me.Width / 2 - Button1.Width / 2), Panel1.Location.Y - Button1.Height) ElseIf Panel1.Height <= 0 Then Timer1.Enabled = False collapsed = True End If Else If Panel1.Height < 200 Then Panel1.Size = New Size(Panel1.Size.Width, Panel1.Size.Height + 5) Button1.Location = New Point(CInt(Me.Width / 2 - Button1.Width / 2), Panel1.Location.Y - Button1.Height) ElseIf Panel1.Height >= 200 Then Timer1.Enabled = False collapsed = False End If End If End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub End Class


Reply With Quote

Cheers 