Solved

changing font size programatically (FontUnit.Parse)

Posted on 2004-08-10
4
2,129 Views
Last Modified: 2013-12-03
I'm trying to change the font size programtically as follows

textBox1.Font.Size = FontUnit.Parse("10");
or
textBox1.Font.Size = FontUnit.Parse("10pt");

and get the following error

Cannot implicitly convert type 'System.Web.UI.WebControls.FontUnit' to 'float'
Property or indexer 'System.Drawing.Font.Size' cannot be assigned to -- it is read only

Is there no way to programtically change the font size because it seems that the Font.Size is read only?

 

0
Comment
Question by:dotnet22
  • 2
4 Comments
 
LVL 4

Expert Comment

by:pashcroft
ID: 11768643
yep just try this:

textBox1.Font.Size = new FontUnit(10);  //creates new font unit of size 10
0
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 11768994
You could not change SIZE property as its readonly but you could change the FONT property
To Change SIZE to 10 , create a new font object with textbox current font and new size value. Assign this font object to the textBox font property.

float size = 10;
textBox1.Font  = new Font(textBox1.Font.FontFamily, size);

This would change font size to 10.

Cheers,
S Sansanwal
0
 
LVL 9

Accepted Solution

by:
s_sansanwal earned 500 total points
ID: 11769015
Sorry, I assumed the question was for Window Application. Fo web application, pashcroft  is right

Cheers,
S Sansanwal
0
 

Author Comment

by:dotnet22
ID: 11776404
sansanwal,

That is exactly what I was looking for.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 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