473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Easiest way for controls to share the size of parent


Maybe I'm tired, but I can't figure out a simple way for two controls to
share the size of the parent control. e.g when the parent's height becomes
NewHeight the first control's new height becomes 0.5*NewHeight and the
second control get the rest i.e 0.5*NewHeight.

A picture says more than 1000 words they say so lets see if there is some
truth in that
I have a Panel with two GroupBoxes
______________________________
| GroupBox1 |
| |
|______________________________|
| GroupBox2 |
| |
|______________________________|

Decreasing the height of the panel should give this result
______________________________
| GroupBox1 |
|______________________________|
| GroupBox2 |
|______________________________|
Surely there's an easy way to achieve this without having to override OnSize
and doing lots
of nasty calculations in there?
I'm starting to really miss the LayoutManagers I have in Java.

Martin


Nov 17 '05 #1
6 1476
there's not a lot of nasty calculations.

groupbox1.Height = panel.Height / 2;

the rest is down to docking.
Dock groupbox1 to Top and groupbox2 to Fill.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Martin" <no@thereisno.ne> wrote in message
news:42******@dnews.tpgi.com.au...

Maybe I'm tired, but I can't figure out a simple way for two controls to
share the size of the parent control. e.g when the parent's height becomes
NewHeight the first control's new height becomes 0.5*NewHeight and the
second control get the rest i.e 0.5*NewHeight.

A picture says more than 1000 words they say so lets see if there is some
truth in that
I have a Panel with two GroupBoxes
______________________________
| GroupBox1 |
| |
|______________________________|
| GroupBox2 |
| |
|______________________________|

Decreasing the height of the panel should give this result
______________________________
| GroupBox1 |
|______________________________|
| GroupBox2 |
|______________________________|
Surely there's an easy way to achieve this without having to override
OnSize and doing lots
of nasty calculations in there?
I'm starting to really miss the LayoutManagers I have in Java.

Martin


Nov 17 '05 #2
there's not a lot of nasty calculations.

groupbox1.Height = panel.Height / 2;

the rest is down to docking.
Dock groupbox1 to Top and groupbox2 to Fill.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Martin" <no@thereisno.ne> wrote in message
news:42******@dnews.tpgi.com.au...

Maybe I'm tired, but I can't figure out a simple way for two controls to
share the size of the parent control. e.g when the parent's height becomes
NewHeight the first control's new height becomes 0.5*NewHeight and the
second control get the rest i.e 0.5*NewHeight.

A picture says more than 1000 words they say so lets see if there is some
truth in that
I have a Panel with two GroupBoxes
______________________________
| GroupBox1 |
| |
|______________________________|
| GroupBox2 |
| |
|______________________________|

Decreasing the height of the panel should give this result
______________________________
| GroupBox1 |
|______________________________|
| GroupBox2 |
|______________________________|
Surely there's an easy way to achieve this without having to override
OnSize and doing lots
of nasty calculations in there?
I'm starting to really miss the LayoutManagers I have in Java.

Martin


Nov 17 '05 #3
Hi,
this is what you can do to proportionally resize all controls in a form

private Hashtable hash = new Hashtable();
private Point OrgSize ;

private void InitOrgRect()
{
OrgSize = new Point( ClientRectangle.Width,ClientRectangle.Height) ;
foreach(Control cl in Controls)
{
Rectangle r = new Rectangle(
cl.Location.X,cl.Location.Y,cl.Width,cl.Height );
hash.Add(cl,r);
}
}

protected override void OnSizeChanged(EventArgs e)
{
if( hash.Count == 0 )
return ;

int widthRatio = ClientRectangle.Width * 100/ OrgSize.X ;
int heightRatio = ClientRectangle.Height * 100/ OrgSize.Y;

foreach (Control ctl in Controls)
{
Rectangle r = (Rectangle)hash[ctl];
ctl.Width = r.Width * widthRatio / 100;
ctl.Height = r.Height * heightRatio / 100;
ctl.Location = new Point((r.X * widthRatio / 100),(r.Y * heightRatio
/ 100));
}
}
Martin wrote:
Maybe I'm tired, but I can't figure out a simple way for two controls to
share the size of the parent control. e.g when the parent's height becomes
NewHeight the first control's new height becomes 0.5*NewHeight and the
second control get the rest i.e 0.5*NewHeight.

A picture says more than 1000 words they say so lets see if there is some
truth in that
I have a Panel with two GroupBoxes
______________________________
| GroupBox1 |
| |
|______________________________|
| GroupBox2 |
| |
|______________________________|

Decreasing the height of the panel should give this result
______________________________
| GroupBox1 |
|______________________________|
| GroupBox2 |
|______________________________|
Surely there's an easy way to achieve this without having to override OnSize
and doing lots
of nasty calculations in there?
I'm starting to really miss the LayoutManagers I have in Java.

Martin


Nov 17 '05 #4
Hi,
this is what you can do to proportionally resize all controls in a form

private Hashtable hash = new Hashtable();
private Point OrgSize ;

private void InitOrgRect()
{
OrgSize = new Point( ClientRectangle.Width,ClientRectangle.Height) ;
foreach(Control cl in Controls)
{
Rectangle r = new Rectangle(
cl.Location.X,cl.Location.Y,cl.Width,cl.Height );
hash.Add(cl,r);
}
}

protected override void OnSizeChanged(EventArgs e)
{
if( hash.Count == 0 )
return ;

int widthRatio = ClientRectangle.Width * 100/ OrgSize.X ;
int heightRatio = ClientRectangle.Height * 100/ OrgSize.Y;

foreach (Control ctl in Controls)
{
Rectangle r = (Rectangle)hash[ctl];
ctl.Width = r.Width * widthRatio / 100;
ctl.Height = r.Height * heightRatio / 100;
ctl.Location = new Point((r.X * widthRatio / 100),(r.Y * heightRatio
/ 100));
}
}
Martin wrote:
Maybe I'm tired, but I can't figure out a simple way for two controls to
share the size of the parent control. e.g when the parent's height becomes
NewHeight the first control's new height becomes 0.5*NewHeight and the
second control get the rest i.e 0.5*NewHeight.

A picture says more than 1000 words they say so lets see if there is some
truth in that
I have a Panel with two GroupBoxes
______________________________
| GroupBox1 |
| |
|______________________________|
| GroupBox2 |
| |
|______________________________|

Decreasing the height of the panel should give this result
______________________________
| GroupBox1 |
|______________________________|
| GroupBox2 |
|______________________________|
Surely there's an easy way to achieve this without having to override OnSize
and doing lots
of nasty calculations in there?
I'm starting to really miss the LayoutManagers I have in Java.

Martin


Nov 17 '05 #5
Take a look at the OnLayout event - you can iterate through the controls in
the Panel and make sure their heights are all the appropriate fraction of
the panel itself.

Steve

"Martin" <no@thereisno.ne> wrote in message
news:42******@dnews.tpgi.com.au...

Maybe I'm tired, but I can't figure out a simple way for two controls to
share the size of the parent control. e.g when the parent's height becomes
NewHeight the first control's new height becomes 0.5*NewHeight and the
second control get the rest i.e 0.5*NewHeight.

A picture says more than 1000 words they say so lets see if there is some
truth in that
I have a Panel with two GroupBoxes
______________________________
| GroupBox1 |
| |
|______________________________|
| GroupBox2 |
| |
|______________________________|

Decreasing the height of the panel should give this result
______________________________
| GroupBox1 |
|______________________________|
| GroupBox2 |
|______________________________|
Surely there's an easy way to achieve this without having to override
OnSize and doing lots
of nasty calculations in there?
I'm starting to really miss the LayoutManagers I have in Java.

Martin


Nov 17 '05 #6
Take a look at the OnLayout event - you can iterate through the controls in
the Panel and make sure their heights are all the appropriate fraction of
the panel itself.

Steve

"Martin" <no@thereisno.ne> wrote in message
news:42******@dnews.tpgi.com.au...

Maybe I'm tired, but I can't figure out a simple way for two controls to
share the size of the parent control. e.g when the parent's height becomes
NewHeight the first control's new height becomes 0.5*NewHeight and the
second control get the rest i.e 0.5*NewHeight.

A picture says more than 1000 words they say so lets see if there is some
truth in that
I have a Panel with two GroupBoxes
______________________________
| GroupBox1 |
| |
|______________________________|
| GroupBox2 |
| |
|______________________________|

Decreasing the height of the panel should give this result
______________________________
| GroupBox1 |
|______________________________|
| GroupBox2 |
|______________________________|
Surely there's an easy way to achieve this without having to override
OnSize and doing lots
of nasty calculations in there?
I'm starting to really miss the LayoutManagers I have in Java.

Martin


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin | last post by:
Maybe I'm tired, but I can't figure out a simple way for two controls to share the size of the parent control. e.g when the parent's height becomes NewHeight the first control's new height becomes...
2
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the...
4
by: TS | last post by:
Steven, i lost this message conversation from outlook express and made a post online (see last one on this page). Please answer it as it hasn't been yet. thanks The clientID of our controls...
6
by: shashi shekhar singh | last post by:
Respected Sir, I am facing problem when i try to deploy my website on iis 7.0 on test page. i have to display some .mht files on iframe in gridview and error looks like below, Server Error in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.