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

Re: how to have two controls resize equally? by Mick

Mick
Fri Jul 16 08:21:43 CDT 2004

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" <Andrew Sharpe@discussions.microsoft.com> wrote in message
news:46E6AA36-C9E6-4440-9EDB-B339F77ABCFC@microsoft.com...
> 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


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004



Re: how to have two controls resize equally? by Mick

Mick
Mon Jul 19 18:25:39 CDT 2004

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" <AndrewSharpe@discussions.microsoft.com> wrote in message
news:4F90F2D4-D1B3-4327-9A4E-A8B91813A073@microsoft.com...
> 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!


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 13/07/2004