Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

setting Font property of Label control in code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David C - 01 Feb 2007 19:06 GMT
This is a very basic question here.  I must be missing something
here.

At run time, I am trying to set the text of the label control bold.

lblMyLabel.Font.Bold = true;

does not work since it's read only (why why why why why).

Thank you.
Oliver Sturm - 01 Feb 2007 19:46 GMT
Hello David,

>At run time, I am trying to set the text of the label control bold.
>
>lblMyLabel.Font.Bold = true;
>
>does not work since it's read only

Use a line like this instead:

  label1.Font.Bold = new Font(label1.Font, FontStyle.Bold);

               Oliver Sturm
Signature

http://www.sturmnet.org/blog

David C - 01 Feb 2007 21:32 GMT
> Hello David,
>
[quoted text clipped - 10 lines]
>                 Oliver Sturm
> --http://www.sturmnet.org/blog

Thank you.  I can't think of a rhyme or reason why Font.Bold property
should be read only.  Can you?
Oliver Sturm - 01 Feb 2007 21:57 GMT
Hello David,

>Thank you.  I can't think of a rhyme or reason why Font.Bold property
>should be read only.  Can you?

Well... sure ;-)

The whole Font handling goes back onto Windows resources outside .NET. On
the API level it's simply not possible to set a property Bold on the font
- after all, for a lot of fonts it's a different font resource that is
being loaded for bold or non-bold display. Check your Windows\Fonts folder
and you'll see that there are several arial*.ttf files - one of them is
the bold version of Arial.

Of course the .NET API could theoretically hide that detail from you and
make the Bold property writable nevertheless. But they decided not to go
that way and I can understand why - the way things are, the user of the
API understands that he's triggering what may be a costly operation.
Otherwise it would have seemed like switching the Bold flag may be a
trivial thing without a lot of overhead.

               Oliver Sturm
Signature

http://www.sturmnet.org/blog


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.