Tuesday, 6 August 2013

Can't change font size of label in C#

Can't change font size of label in C#

I am using Visual Studio 2010 to build a very simple form. It all works
fine except I need to dynamically draw a label onto the form. I can draw
the label, but when I try and change the newlabel.Font.Size attribute, I
get this error:
Property or indexer 'System.Drawing.Font.Size' cannot be assigned to -- it
is read only
What does this mean and how can I fix it? This is my first ever C#
program, so please cut me some slack if I'm doing something really stupid.
Here is my code for drawing the label:
Label newlabel = new Label();
newlabel.Text = "BOOM";
newlabel.Font.Size = 72;//This causes the error
newlabel.ForeColor = Color.White;
newlabel.Location = new Point(250,250);
newlabel.AutoSize = false;
this.Controls.Add(newlabel);

No comments:

Post a Comment