Results 1 to 16 of 16

Thread: Slide panel out of form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    101

    Slide panel out of form

    Hey!


    Is it possible to slide a panel out of the actual form? Like you press a button then the panel slides all the way left and then out ? Then it should be able to come back too ?


    Is this possible? Any ideas?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Slide panel out of form

    Do you mean into the form, a la the Toolbox and other windows in VS, or do you out of the form?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: Slide panel out of form


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    101

    Re: Slide panel out of form

    That one worked Paul, it's also exactly what i'm looking for. But I have no idea how its working or even how to call it.

    I suspect this is a custom panel control? Could you help me out a bit?

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

    Re: Slide panel out of form

    it is a custom panel control.
    you need to add slideOutPanel.vb to your project, then after rebuilding you'll find slideOutPanel at the top of your toolbox + you add it just as any control.

    to add controls to it at design time, resize it by dragging the border, + after resize it back to closedWidth.

    when you run your project it should work as in my demo project

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    101

    Re: Slide panel out of form

    Is there any way to make it slide smoother? Thanks by the way.

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

    Re: Slide panel out of form

    try changing the timer interval + the line that sets the width values in tmr_tick

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    101

    Re: Slide panel out of form

    Okay I managed to modify the interval and the positions so it becomes smooth and nice. However I got another problem.

    I put a button in the panel by dragging a button from the toolbox and putting it inside the panel on the designer. I highlighted the panel with my mouse, and the panel slided nice and smooth and the button showed up. However when i highlight the button inside the panel, the panel is closing :/

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,375

    Re: Slide panel out of form

    I also have a slide out panel example in the codebank, I have it set up in my signature.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

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

    Re: Slide panel out of form

    Quote Originally Posted by Crystalii View Post
    Okay I managed to modify the interval and the positions so it becomes smooth and nice. However I got another problem.

    I put a button in the panel by dragging a button from the toolbox and putting it inside the panel on the designer. I highlighted the panel with my mouse, and the panel slided nice and smooth and the button showed up. However when i highlight the button inside the panel, the panel is closing :/
    ok. try this:

    vb.net Code:
    1. Imports System.Drawing.Drawing2D
    2.  
    3. Public Class slideOutPanel
    4.     Inherits Panel
    5.  
    6.     Dim polygon() As Point
    7.     Dim closedWidth As Integer
    8.     Dim maxWidth As Integer = 200
    9.  
    10.     Dim caption As String = "Slide Out Panel"
    11.  
    12.     Dim closing As Boolean = False
    13.  
    14.     Private WithEvents tmr As New Timer
    15.  
    16.  
    17.     Public Sub New()
    18.  
    19.         Me.Dock = DockStyle.Right
    20.         Dim s As SizeF = Me.CreateGraphics.MeasureString(caption, Me.Font)
    21.  
    22.         Dim gp As New GraphicsPath
    23.         polygon = New Point() {New Point(0, 0), New Point(300, 0), New Point(300, 300), New Point(CInt(s.Height), 300), New Point(CInt(s.Height), CInt(s.Width)), New Point(0, CInt(s.Width)), New Point(0, 0)}
    24.         gp.AddPolygon(polygon)
    25.         Me.Region = New Region(gp)
    26.         closedWidth = CInt(s.Height)
    27.         Me.Width = CInt(s.Height)
    28.  
    29.         polygon(2).X -= 1
    30.         polygon(3).Y -= 1
    31.         polygon(4).Y -= 1
    32.         polygon(5).Y -= 1
    33.  
    34.         tmr.Interval = 100
    35.  
    36.         add_handlers(Me)
    37.  
    38.     End Sub
    39.  
    40.     Private Sub add_handlers(ByVal c As Control)
    41.         For Each ctrl As Control In c.Controls
    42.             AddHandler c.MouseEnter, AddressOf handler
    43.             If ctrl.Controls.Count > 0 Then
    44.                 add_handlers(ctrl)
    45.             End If
    46.         Next
    47.     End Sub
    48.  
    49.     Private Sub handler(ByVal sender As Object, ByVal e As EventArgs)
    50.         OnMouseEnter(e)
    51.     End Sub
    52.  
    53.     Private Sub slideOutPanel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    54.         e.Graphics.DrawPolygon(Pens.Black, polygon)
    55.         e.Graphics.TranslateTransform(closedWidth, 0)
    56.         e.Graphics.RotateTransform(90)
    57.         e.Graphics.DrawString(caption, Me.Font, Brushes.Black, 0, 0)
    58.         e.Graphics.ResetTransform()
    59.     End Sub
    60.  
    61.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
    62.         closing = False
    63.         tmr.Enabled = True
    64.         MyBase.OnMouseEnter(e)
    65.     End Sub
    66.  
    67.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
    68.         closing = True
    69.         tmr.Enabled = True
    70.         MyBase.OnMouseLeave(e)
    71.     End Sub
    72.  
    73.     Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
    74.         If closing Then
    75.             Me.Width -= Math.Min(50, Me.Width - closedWidth)
    76.         Else
    77.             Me.Width += Math.Min(50, maxWidth - Me.Width)
    78.         End If
    79.         tmr.Enabled = If(Me.Width = closedWidth Or Me.Width = maxWidth, False, True)
    80.     End Sub
    81. End Class
    Last edited by .paul.; Nov 3rd, 2012 at 08:26 PM.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    101

    Re: Slide panel out of form

    The same problem exists unfortunately Paul :/

    I will take a look at yours soon dday9.

    Thanks.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    101

    Re: Slide panel out of form

    I liked your sliding control too dday9. It got no problems. However it is starting opened. Is there any way you can make it start closed?

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

    Re: Slide panel out of form

    i fixed the bugs in mine. sorry i couldn't help much earlier... been busy:

    vb.net Code:
    1. Imports System.Drawing.Drawing2D
    2.  
    3. Public Class slideOutPanel
    4.     Inherits Panel
    5.  
    6.     Dim polygon() As Point
    7.  
    8.     Dim closedWidth As Integer
    9.     Dim captionHeight As Integer
    10.  
    11.     Dim maxWidth As Integer = 200
    12.  
    13.     Dim caption As String = "Slide Out Panel"
    14.  
    15.     Dim closing As Boolean = False
    16.  
    17.     Private WithEvents tmr As New Timer
    18.  
    19.  
    20.     Public Sub New()
    21.  
    22.         Me.Dock = DockStyle.Right
    23.         Dim s As SizeF = Me.CreateGraphics.MeasureString(caption, Me.Font)
    24.  
    25.         Dim gp As New GraphicsPath
    26.         polygon = New Point() {New Point(0, 0), New Point(300, 0), New Point(300, 300), New Point(CInt(s.Height), 300), New Point(CInt(s.Height), CInt(s.Width)), New Point(0, CInt(s.Width)), New Point(0, 0)}
    27.         gp.AddPolygon(polygon)
    28.         Me.Region = New Region(gp)
    29.         closedWidth = CInt(s.Height)
    30.         captionHeight = CInt(s.Width)
    31.         Me.Width = CInt(s.Height)
    32.  
    33.         polygon(2).X -= 1
    34.         polygon(3).Y -= 1
    35.         polygon(4).Y -= 1
    36.         polygon(5).Y -= 1
    37.  
    38.         tmr.Interval = 100
    39.        
    40.     End Sub
    41.  
    42.     Private Sub slideOutPanel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    43.         e.Graphics.DrawPolygon(Pens.Black, polygon)
    44.         e.Graphics.RotateTransform(270)
    45.         e.Graphics.DrawString(caption, Me.Font, Brushes.Black, -captionHeight, 0)
    46.         e.Graphics.ResetTransform()
    47.     End Sub
    48.  
    49.     Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
    50.         closing = False
    51.         tmr.Enabled = True
    52.         MyBase.OnMouseEnter(e)
    53.     End Sub
    54.  
    55.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
    56.         Dim p As Point = Me.PointToClient(Cursor.Position)
    57.         If Not Me.Region.IsVisible(p) Then
    58.             closing = True
    59.             tmr.Enabled = True
    60.         End If
    61.         MyBase.OnMouseLeave(e)
    62.     End Sub
    63.  
    64.     Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
    65.         If closing Then
    66.             Me.Width -= Math.Min(50, Me.Width - closedWidth)
    67.         Else
    68.             Me.Width += Math.Min(50, maxWidth - Me.Width)
    69.         End If
    70.         tmr.Enabled = If(Me.Width = closedWidth Or Me.Width = maxWidth, False, True)
    71.     End Sub
    72. End Class

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    101

    Re: Slide panel out of form

    Thank you, that solved all the bugs

  15. #15
    Lively Member
    Join Date
    Feb 2012
    Posts
    81

    Re: Slide panel out of form

    I know this thread is quite old, but is it possible to make it slide from the left instead of the right?

    Thanks
    LB

  16. #16
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,375

    Re: Slide panel out of form

    Start a new thread!

    Take a look at this contribution I made: http://www.vbforums.com/showthread.p...ols&highlight=
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

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