Results 1 to 5 of 5

Thread: amend readonly properties

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    57

    amend readonly properties

    hi
    How do i amend the read only properteis like font.underline, font.height etc
    I know its read only but there must be a way to amnd these.

    This is for writing fractions in vb

  2. #2
    Addicted Member
    Join Date
    Jun 2009
    Posts
    245

    Re: amend readonly properties

    If you want to set the font style for example a label, you have to construct a new font, and assign that font to the label. Something like this...

    Code:
    Label1.Font = New Font("Microsoft Sans Serif", 11, FontStyle.Underline)
    Not quite sure if that's what you wanted though...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: amend readonly properties

    Note that, if you want to change the style of an existing Font, there's a constructor provided specifically for that:
    vb.net Code:
    1. 'Apply the Bold style.
    2. myFont = New Font(myFont, myFont.Style Or FontStyle.Bold)
    3.  
    4. 'Remove the Bold style.
    5. myFont = New Font(myFont, myFont.Style And Not FontStyle.Bold)
    6.  
    7. 'Toggle the Bold style.
    8. myFont = New Font(myFont, myFont.Style Xor FontStyle.Bold)
    Just to elablorate a bit, Font objects are immutable by design. That means that, once created, you cannot change a Font. The reason for this is that making them changeable would require the class to be considerably more complex and Microsoft decided that keeping the class lightweight was preferable to making it mutable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    57

    Re: amend readonly properties

    Thanks, the underline worked. What if I want to change the line spacing i.e reduce them.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: amend readonly properties

    As far as I'm aware the Height of a Font is determined by the creator of the font, not the user. If you want more space between your lines then you need to use GDI+ to draw the text and add the padding yourself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width