Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

There is no "work around." This is not a bug, it is by design. (Do I sound like I work at Microsoft?) Font objects are "Immutable," i.e. you can not modify them once created, just like strings (notice that all string functions return a new string object). In order to change the size or style of a font you must create a new System.Drawing.Font object.

 

Fortunately Microsoft made made a constructor that accepts a prototype font and allows you to specify a style, like so:

' Make this control's font bold, not italic, not underlined, and not strikethru:
Me.Font = New Font(this.Font, FontStyle.Bold)

If you need to change size too then you need to use a normal constructor.

' Make this control's font size 16 bold italic
Me.Font = New Font(Me.Font.FontFamily, 16, FontStyle.Bold or FontStyle.Italic)

[sIGPIC]e[/sIGPIC]
Posted

Many Thanks.

 

There is no "work around." This is not a bug, it is by design. (Do I sound like I work at Microsoft?) Font objects are "Immutable," i.e. you can not modify them once created, just like strings (notice that all string functions return a new string object). In order to change the size or style of a font you must create a new System.Drawing.Font object.

 

Fortunately Microsoft made made a constructor that accepts a prototype font and allows you to specify a style, like so:

' Make this control's font bold, not italic, not underlined, and not strikethru:
Me.Font = New Font(this.Font, FontStyle.Bold)

If you need to change size too then you need to use a normal constructor.

' Make this control's font size 16 bold italic
Me.Font = New Font(Me.Font.FontFamily, 16, FontStyle.Bold or FontStyle.Italic)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...