bjwade62 Posted October 11, 2006 Posted October 11, 2006 Anyone know why Label.font.size and Label.font.bold are read only at runtime in .NET? Is there a work around? Quote
Leaders snarfblam Posted October 11, 2006 Leaders Posted October 11, 2006 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) Quote [sIGPIC]e[/sIGPIC]
bjwade62 Posted October 12, 2006 Author Posted October 12, 2006 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) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.