Thursday, July 24, 2008

Changing a Control's Font Size at Runtime in VB.NET

If you have a control that is using a font with size 8.25 (which was defined at design-time), then at runtime you want to change it to a different size (such as 12), you cannot simply say:

ctrl.Font.Size = 12 (this will not work - Property Size is Read-Only)

However, you can replace the whole font:

ctrl.Font = new Font(ctrl.Font.FontFamily, 12, ctrl.Font.Style)

For more info and examples in C#, see: http://bytes.com/forum/thread261450.html

5 comments:

  1. Hi!
    This was a great example, i was working on a listbox where i needed to be able to change the fontsize in runtime and after hours of searching the net i found this.

    Thank you very much!

    ReplyDelete
  2. hi=) ..tnx 4 the gud example!! more power..its a great help!


    thk u vry mch=)...

    ReplyDelete
  3. Great. Thanks. This realy helps my school project =D

    ReplyDelete
  4. Great help! Good contribution...

    ReplyDelete

Note: Only a member of this blog may post a comment.