how to have two controls resize equally?

G

Guest

Say I have two panels (or any control for that matter) on a form. When the form is resized, I want the panels to resize equally, so that they always each occupy 50% of the available area of the form.

I've messed around with docking and anchoring but can't seem to find a combination that works.

Andrew
 
M

Mick Doherty

Dock Panel1 to Top
Dock Panel2 to Fill
Bring Panel2 to Front

In the form Resize Method

vb.net
Panel.Height = ClientSize.Height \2

c#
panel1.Height = ClientSize.Height/2;

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Andrew Sharpe said:
Say I have two panels (or any control for that matter) on a form. When
the form is resized, I want the panels to resize equally, so that they
always each occupy 50% of the available area of the form.
 
M

Mick Doherty

Roll your own Panel and use that instead.

Create a new usercontrol.
Change the control to Inherit form Panel instead of User Control.
Add the Following Code:

\\\
Private WithEvents MyParent As Control

Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
MyParent = Me.Parent
End Sub

Private Sub MyParent_Resize(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyParent.Resize
Me.Height = MyParent.ClientSize.Height \ 2
End Sub
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Andrew Sharpe said:
Is there a way to do it other than within the resize code? I need this
functionality in many, many places. Surely there is a large need for this?
VB.NET's docking and anchoring functionalities have spoiled me on control
resizing, I don't want to code any of it myself if I don't have to!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top