Solved

changing font size programatically (FontUnit.Parse)

Posted on 2004-08-10
4
2,116 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
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…

863 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

28 Experts available now in Live!

Get 1:1 Help Now