Label Font.Size

I am placing a label onto a form programically...

Label objId;

objId =new Label();

objId.BackColor = Color.Transparent;

objId.ForeColor = Color.Blue;

// objId.Font.Size = 22; //Read Only?

objId.Text = "TEST";

pictureBox1.Controls.Add(objId);

I can't seem to find the right way to simply change the font size.

Thanks,

Zath

[588 byte] By [Zath] at [2007-12-18]
# 1

You cannot change just the font size, instead you need give it a new Font instance, and to maintain any additional Font information from the previous instance you'd want to use the previous instance to create the new one ala:

objId.Font = new Font(objId.Font.FontFamily, newFontSize, objId.Font.Style);

where newFontSize is the size you want for the new font.

BrendanGrant at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

Thanks! Never had to change the font programically and you would think it was built in like the backcolor and so forth.

Zath

Zath at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...