Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

How to dynamically change a controls font

Dear Sirs,

My vb windows app dynamically creates label controls.  What I need to do is dynamically set the font name and size at runtime but i'm being told that the .font.name etc parameters are read only.

Is there anyway I can set these values at runtime?
0
watersidedesigns
Asked:
watersidedesigns
1 Solution
 
AlexFMCommented:
Control.Font Property is not read-only and allows to get font and to set new font.

MyControl.Font = New Font(MyControl.Font, MyControl.Font.Style Or FontStyle.Bold)   ' set bold font

See additional details in Control.Font Property MSDN topic.


0
 
S-TwilleyCommented:
the font class that it returns has read only properties, like bold, italic and such... which (as AlexFM showed) can be used as a base to create  a new font class... if all your labels use a finite set of fonts, then i'd suggest creating these at run-time and declaring them at class level, and setting the label's font property to these, so you're not creating the fonts over and over again.
0
 
watersidedesignsAuthor Commented:
Thanks Guys
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now