Solved  - resize form

Posted on 2006-05-30
Last Modified: 2012-06-21
Have a panel in center of form.  
I need to be able to collapse the form to the left edge of the panel upon a click of a button.

Seems easy enough with panel.location = new point(0,0) then resize my form but  I need to make sure my panel does not move.

So essentially looking for a way to expand and contract the form from the left of my panel.

Thanks all!  
Question by:TechMonster
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    How about...

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Me.ClientSize.Width > Panel1.Left Then
                Me.Tag = Me.ClientSize.Width
                Me.ClientSize = New Size(Panel1.Left, Me.ClientSize.Height)
                Me.ClientSize = New Size(Me.Tag, Me.ClientSize.Height)
            End If
        End Sub

    Author Comment

    The form expands to the right.  
    Need to have the form expand to the left.
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Gotcha...lemme play with it...
    LVL 85

    Accepted Solution

    If you have VB.Net 2005, then we can use a SplitContainer control:

    Set the FixedPanel() property to Panel1 (the left Panel) and the IsSplitterFixed() property set to True:

        Private Panel1Width As Integer
        Private Panel2Width As Integer

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Panel1Width = SplitContainer1.Panel1.Width
            Panel2Width = SplitContainer1.Panel2.Width
        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Not SplitContainer1.Panel1Collapsed Then
                SplitContainer1.Panel1Collapsed = True
                Me.ClientSize = New Size(Panel2Width, Me.ClientSize.Height)
                SplitContainer1.Panel1Collapsed = False
                Me.ClientSize = New Size(Panel1Width + Panel2Width, Me.ClientSize.Height)
            End If
        End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now