How to dynamically change a controls font

Posted on 2005-04-11
Last Modified: 2013-12-03
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 etc parameters are read only.

Is there anyway I can set these values at runtime?
Question by:watersidedesigns
    LVL 48

    Accepted Solution

    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.

    LVL 12

    Expert Comment

    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.

    Author Comment

    Thanks Guys

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now