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:

Anonymous said...

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!

Anonymous said...

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


thk u vry mch=)...

Anonymous said...

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

Shashank Purohit said...

Thanks.. It helped me a lot..

Anonymous said...

Great help! Good contribution...