Properties of Font-class are all read-only ???


C

Christian Cambier

Hi,

the following produces a compiler error :

label1.Font.Size = 10;

==> ERROR:property or indexer 'System.Drawing.Font.Size' cannot be
assigned to -- it is read only

OK, but why has it been designed as read-only. As are all properties of the
Font-class by the way (???)

Is there no way I can set the individual properties of a Font-object ?

thnx

Chris
 
Ad

Advertisements

G

Guest

Christian

I think the font object's properties are read only because of the underlying implementation in windows. (See CreateFont API for more info). If you want to change the size, create a new instance of font passing the same family etc... but a different size

Hope that help
Jackson Davis [MSFT
-
This posting is provided "AS IS" with no warranties, and confers no rights
OR if you wish to include a script sample in your post please add "Use o
included script samples are subject to the terms specified a
http://www.microsoft.com/info/cpyright.htm
 
Ad

Advertisements

P

Pete Davis

No, once you create a font, you can't change it. There are a number of
reasons for this, but it's all basically because that's the way fonts are
handled in Windows. A 12 point font and a 10 point font that are otherwise
identical are considered two entirely separate fonts.

Underneath, each has a separate font handle and thus the encapsulation in
..NET works the same way.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top