Label.Font.

G

Guest

Hello:

I have array of Label controls allocated danamically.

When I'm trying to change font as:
LabelLeft.Font.Strikeout = false;

I have error:

"Property or indexer 'System.Drawing.Font.Strikeout' cannot be assigned to
-- it is read only"

Thank you.
 
M

Michael C

dave said:
Hello:

I have array of Label controls allocated danamically.

When I'm trying to change font as:
LabelLeft.Font.Strikeout = false;

I have error:

"Property or indexer 'System.Drawing.Font.Strikeout' cannot be assigned to
-- it is read only"


I'd guess you need to create a new font.

MyLabel.Font = new Font(blah, blah);

Michael
 
L

Larry Lard

dave said:
Hello:

I have array of Label controls allocated danamically.

When I'm trying to change font as:
LabelLeft.Font.Strikeout = false;

I have error:

"Property or indexer 'System.Drawing.Font.Strikeout' cannot be assigned to
-- it is read only"


What we think of as 'changing a property of the font' must be expressed
as 'assigning a new font which is the same as the old font except for
that particular property'. This code flips the current strikeoutness:


bool isStruckOut = LabelLeft.Font.Strikeout;
Font currentFont = LabelLeft.Font;

if (isStruckOut)
// to remove a style component we must get the
// current style and unset the relevant bit
// with a bitmask
LabelLeft.Font = new Font(currentFont,
currentFont.Style & ~FontStyle.Strikeout);
else
// adding a style component is easy
LabelLeft.Font = new Font(currentFont,
FontStyle.Strikeout);
 
S

Sericinus hunter

dave said:
Hello:
I have array of Label controls allocated danamically.
When I'm trying to change font as:
LabelLeft.Font.Strikeout = false;

I have error:

"Property or indexer 'System.Drawing.Font.Strikeout' cannot be assigned to
-- it is read only"


Try:

LabelLeft.Font = new Font(LabelLeft.Font, LabelLeft.Font.Style & ~FontStyle.Strikeout);
 

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