Jul 05
An inspection of the Font class will reveal that every public property is read-only. This means to change a font's size, you need to create a new Font object with all the same properties of your current font but with the new size. Here is a handy method to do just that:
static public Font ChangeFontSize( Font font, float fontSize ) { if (font != null) { float currentSize = font.Size; if (currentSize != fontSize) { font = new Font( font.Name, fontSize, font.Style, font.Unit, font.GdiCharSet, font.GdiVerticalFont ); } } return font; }
For example, to double the size of a label's font:
label.Font = ChangeFontSize( label.Font, label.Font.Size * 2 );
Graphics Unit
Note the method above uses the same GraphicsUnit (point, pixel, millimeter, etc.) as the original font. You may want to overload this method to also accept a specific unit:
static public Font ChangeFontSize( Font font, float fontSize, GraphicsUnit unit ) { if (font != null) { float currentSize = font.Size; if (currentSize != fontSize) { font = new Font( font.Name, fontSize, font.Style, unit, font.GdiCharSet, font.GdiVerticalFont ); } } return font; }
For example, to resize a label's font to 12 pixels:
label.Font = ChangeFontSize( label.Font, 12.0F, GraphicsUnit.Pixel );
Copyright © 2007-8 Tiwebb Ltd. All rights reserved. This material may not be published, broadcast, rewritten or redistributed without explicit permission from Tiwebb Ltd.

hi
without success !!! Why ? is there a way to use this kind of font name ("Tahoma") ?
i tried to use the vb version of your code :
i tried : Lbl.Font = ChangeFontSize("Tahoma",
thanks
Public Shared Function ChangeFontSize(ByVal font As Font, ByVal fontSize As Single) As Font
If font IsNot Nothing Then
Dim currentSize As Single = font.Size
If currentSize fontSize Then
font = New Font(font.Name, fontSize, font.Style, font.Unit, font.GdiCharSet, font.GdiVerticalFont)
End If
End If
Return font
End Function
Re: i tried : Lbl.Font = ChangeFontSize("Tahoma", without success !!! Why ? is there a way to use this kind of font name ("Tahoma") ?
The first argument of the ChangeFontSize function is a Font object, and you are attempting to pass it a string ("Tahoma").
The ChangeFontSize function was provided to change the size of an existing font. What you are trying to do is change to another font altogether (Tahoma in your example). In that case, you can create a new Font object:
Lbl.Font = New Font("Tahoma", 12.0F)
thank`s you hellp me in my project by this code
Ok, already it works.
It's a nice trick! Thanks.
gets this below error in line (lbobjective.font parameter)
lbObjective.Font = ChangeFontSize(lbObjective.Font , fontSizeta2);
Error cannot convert from 'System.Web.UI.WebControls.FontInfo' to 'System.Drawing.Font'
Fonts = ((DropDownList)Master.FindControl("ddlLanguage")).SelectedValue;
if (Fonts == "ta-IN")
{
Double fontSizeta = Convert.ToDouble(lbObjective.Font.Size);
fontSizeta = fontSizeta * 0.8;
float fontSizeta2 = (float)fontSizeta;
lbObjective.Font = ChangeFontSize(lbObjective.Font , fontSizeta2);
}
static public Font ChangeFontSize(Font font, float fontSize)
{
if (font != null)
{
float currentSize = font.Size;
if (currentSize != fontSize)
{
font = new Font(font.Name, fontSize,
font.Style, font.Unit,
font.GdiCharSet, font.GdiVerticalFont);
}
}
return font;
}
help me in solving this ir would be grateful
Thanks in advance
What is lbObjective? From the info you provided, it appears that lbObjective.Font is a FontInfo and not a Font.