• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

VB.net - resize form

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!  
0
TechMonster
Asked:
TechMonster
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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)
        Else
            Me.ClientSize = New Size(Me.Tag, Me.ClientSize.Height)
        End If
    End Sub
0
 
TechMonsterAuthor Commented:
The form expands to the right.  
Need to have the form expand to the left.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Gotcha...lemme play with it...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you have VB.Net 2005, then we can use a SplitContainer control:
http://www.windowsforms.net/WhidbeyFeatures/default.aspx?PageID=2&ItemID=10&Cat=Controls&tabindex=5

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)
        Else
            SplitContainer1.Panel1Collapsed = False
            Me.ClientSize = New Size(Panel1Width + Panel2Width, Me.ClientSize.Height)
        End If
    End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now