Resize components in a Form

P

Poul C

Hello



With the code below I can resize all the components on a Form when ever the
Form resizes.

For the time beeing it dosn't allow a component to contain another
component, but with a little extra work I can make it work at any dept!

Problem: I can change Left,Top,Width,Height, but I can change the
Font.Size.

Can anybody help me?
Thanks in advance



Best regards

Poul C





// ---- further explanation -----------



Form1_Load: Left,Top,Width,Height are saved in the "Tag" property,
seperated with ";"

Form1_Resize: the components old values for Left,Top,Width,Height are
multiplyed by a factor = newFormSize/oldFormSize
I can use Left,Top,Width,Height without "type-casting" all-though I am using
a "super-component", because all components have the Left,Top,Width,Height
properties.

Of course I can't do the same to the proterty "Font.Size", because all
components do not have that property!!
I have tryed to change the line:

cc.Font = new System.Drawing.Font ("Verdana", 10,
System.Drawing.FontStyle.Bold);

to:

Label ccc = (System.Windows.Forms.Label)cc;

ccc.Font = new System.Drawing.Font ("Verdana",
10,System.Drawing.FontStyle.Bold);



But this dosn't work either!



Please read the remarks in this code:
//------ code ------

private void Form1_Load(object sender, System.EventArgs e) {
// Left,Top,Width,Height are saved in the "Tag" property,
separated with ";"

foreach (Control cc in Controls) cc.Tag = cc.Left+ ";" +
cc.Top+";"+cc.Width+";"+cc.Height;
}


private void Form1_Resize(object sender, System.EventArgs e) {
char[] sep = {';'};
Array a;
foreach (Control cc in Controls)
{
a = ((String)cc.Tag).Split(sep);
// This works fine! ==>
cc.Left =
(int)(this.DisplayRectangle.Width*int.Parse((String)a.GetValue(0))/800);
cc.Top =
(int)(this.DisplayRectangle.Height*int.Parse((String)a.GetValue(1))/600);
cc.Width =(int)(this.DisplayRectangle.Width*
int.Parse((String)a.GetValue(2))/800);
cc.Height
=(int)(this.DisplayRectangle.Height*int.Parse((String)a.GetValue(3))/600);
if
(cc.GetType()==Type.GetType("System.Windows.Forms.Label")) {//<= only Labels
goes here!
// Here is the problem: the size of the Font
does not change!!
cc.Font = new System.Drawing.Font
("Verdana", 10, System.Drawing.FontStyle.Bold);
// The 10 is only for test purpose
}

// Test purpose: this works fine! ==>
label1.Font = new System.Drawing.Font ("Verdana", 10,
System.Drawing.FontStyle.Bold);

}
 
P

Poul C

Hello again!

Yes, - I'll bee the first to answer my own letter:

Poul C said:
Problem: I can change Left,Top,Width,Height, but I can change the
Font.Size.

This line should read:
Problem: I can change Left,Top,Width,Height, but I can * n o t * change the
Font.Size.

Best regards Poul C
 
R

R

You can't change just onw of the Font properties!

You need to do something like:
foo.Font = new System.Drawing.Font("Arial", 17F);

R
--
Due to heavy (20,000+/week!!) spam reception, I use a fake email.
Please reply in this group, which would help others as well.

Help fight spam:
NEVER reply to spam
NEVER buy anything from spamers
NEVER unsubscribe from a spam-list
 
P

Poul C

Hello R

R said:
You can't change just onw of the Font properties!

You need to do something like:
foo.Font = new System.Drawing.Font("Arial", 17F);
R

I kwow, - and that was just what I was doing (source-code at the bottom af
my letter):

cc.Font = new System.Drawing.Font ("Verdana",
10,System.Drawing.FontStyle.Bold);

or:

Label ccc = (System.Windows.Forms.Label)cc;

ccc.Font = new System.Drawing.Font
("Verdana",10,System.Drawing.FontStyle.Bold);


Best regards Poul C
 

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