473,378 Members | 1,427 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,378 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 1474
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.