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);
To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.
To make a label control resize dynamically to fit its contents. Set its AutoSize property to true .
You have to create a new font using: newlabel.Font = new Font(fontFamily, size);
try this
newlabel.Font = new Font(newlabel.Font.FontFamily, Fontsize);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With