By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,317 Members | 2,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,317 IT Pros & Developers. It's quick & easy.

Label.Font.

P: n/a
Hello:

I have array of Label controls allocated danamically.

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

I have error:

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

Thank you.

May 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"dave" <da**@discussions.microsoft.com> wrote in message
news:E5**********************************@microsof t.com...
Hello:

I have array of Label controls allocated danamically.

When I'm trying to change font as:
LabelLeft[i].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
May 9 '06 #2

P: n/a

dave wrote:
Hello:

I have array of Label controls allocated danamically.

When I'm trying to change font as:
LabelLeft[i].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[i].Font.Strikeout;
Font currentFont = LabelLeft[i].Font;

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

--
Larry Lard
Replies to group please

May 10 '06 #3

P: n/a
dave wrote:
Hello:
I have array of Label controls allocated danamically.
When I'm trying to change font as:
LabelLeft[i].Font.Strikeout = false;

I have error:

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


Try:

LabelLeft[i].Font = new Font(LabelLeft[i].Font, LabelLeft[i].Font.Style & ~FontStyle.Strikeout);
May 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.