Solved

changing font size programatically (FontUnit.Parse)

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sources to create infographic resume 2 69
Name Space error VS2015 1 47
Why use this lambda? 12 94
linq .concat equivalent with expression syntax 4 41
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Suggested Courses

739 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