?
Solved

changing font size programatically (FontUnit.Parse)

Posted on 2004-08-10
4
Medium Priority
?
2,163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

762 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