Label.Font.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dave

    Label.Font.

    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.

  • Michael C

    #2
    Re: Label.Font.

    "dave" <dave@discussio ns.microsoft.co m> wrote in message
    news:E5138371-4CD1-4753-8CB5-C8E51BEB3A7E@mi crosoft.com...[color=blue]
    > 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"[/color]

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

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

    Michael


    Comment

    • Larry Lard

      #3
      Re: Label.Font.


      dave wrote:[color=blue]
      > 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"[/color]

      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(currentFon t,
      currentFont.Sty le & ~FontStyle.Stri keout);
      else
      // adding a style component is easy
      LabelLeft[i].Font = new Font(currentFon t,
      FontStyle.Strik eout);

      --
      Larry Lard
      Replies to group please

      Comment

      • Sericinus hunter

        #4
        Re: Label.Font.

        dave wrote:[color=blue]
        > 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"[/color]

        Try:

        LabelLeft[i].Font = new Font(LabelLeft[i].Font, LabelLeft[i].Font.Style & ~FontStyle.Stri keout);

        Comment

        Working...