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);
}
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);
}