How to change the font size without creating a new font

Is it possible to change the font size in .net winforms without creating a new font with a new size?

+4
source share
3 answers

No. Font size is available only for existing Font objects.

+4
source

You can do something similar with the extension method.

Imports System.Runtime.CompilerServices Module FontExtensions <Extension()> Public Function ToSize(ByVal OriginalFont As Font, ByVal NewSize As Single) As Font Dim NewFont As Font NewFont = New Font(OriginalFont.FontFamily, NewSize, OriginalFont.Style) Return NewFont End Function End Module 

and then call it like this:

 SomeObject.Font = Font.ToSize(12) 

It still creates the new font backstage, but your application code is not cluttered with the creation process.

+7
source

Make sure you use the constructor method, which allows you to use the base font and pass in the new desired size. This will save you some code from other approaches.

0
source

All Articles