Solved

changing font size programatically (FontUnit.Parse)

Posted on 2004-08-10
4
2,108 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, I assumed the question was for Window Application. Fo web application, pashcroft  is right

Cheers,
S Sansanwal
0
 

Author Comment

by:dotnet22
Comment Utility
sansanwal,

That is exactly what I was looking for.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now